feat: implement wiki and submission management services with corresponding database schema and API endpoints
Build and Release / release (push) Successful in 2m3s
Build and Release / release (push) Successful in 2m3s
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"history-api/pkg/cache"
|
||||
"history-api/pkg/constants"
|
||||
"history-api/pkg/convert"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
@@ -25,6 +26,8 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
var blockquoteRegex = regexp.MustCompile(`(?is)<blockquote\b[^>]*>.*?</blockquote>`)
|
||||
|
||||
type SubmissionService interface {
|
||||
CreateSubmission(ctx context.Context, userID string, dto *request.CreateSubmissionDto) (*response.SubmissionResponse, *fiber.Error)
|
||||
UpdateSubmissionStatus(ctx context.Context, reviewerID string, submissionID string, dto *request.UpdateSubmissionStatusDto) (*response.SubmissionResponse, *fiber.Error)
|
||||
@@ -888,10 +891,16 @@ func (s *submissionService) applySnapshot(ctx context.Context, tx pgx.Tx, projec
|
||||
}
|
||||
versionTitle := fmt.Sprintf("Version %d", count+1)
|
||||
|
||||
var preview pgtype.Text
|
||||
if match := blockquoteRegex.FindString(wiki.Doc); match != "" {
|
||||
preview = convert.StringToText(match)
|
||||
}
|
||||
|
||||
_, err = wikiRepo.CreateContent(ctx, sqlc.CreateWikiContentParams{
|
||||
WikiID: wikiUUID,
|
||||
Title: versionTitle,
|
||||
Content: convert.StringToText(wiki.Doc),
|
||||
Preview: preview,
|
||||
})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create wiki content: "+err.Error())
|
||||
@@ -912,10 +921,16 @@ func (s *submissionService) applySnapshot(ctx context.Context, tx pgx.Tx, projec
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create wiki: "+err.Error())
|
||||
}
|
||||
|
||||
var preview pgtype.Text
|
||||
if match := blockquoteRegex.FindString(wiki.Doc); match != "" {
|
||||
preview = convert.StringToText(match)
|
||||
}
|
||||
|
||||
_, err = wikiRepo.CreateContent(ctx, sqlc.CreateWikiContentParams{
|
||||
WikiID: wikiUUID,
|
||||
Title: "Version 1",
|
||||
Content: convert.StringToText(wiki.Doc),
|
||||
Preview: preview,
|
||||
})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create wiki content: "+err.Error())
|
||||
|
||||
@@ -124,6 +124,7 @@ func (s *wikiService) GetWikiContentByID(ctx context.Context, id string) (*respo
|
||||
WikiID: content.WikiID,
|
||||
Title: content.Title,
|
||||
Content: content.Content,
|
||||
Preview: content.Preview,
|
||||
CreatedAt: content.CreatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user