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:
@@ -26,5 +26,6 @@ type WikiContentResponse struct {
|
||||
WikiID string `json:"wiki_id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Preview string `json:"preview"`
|
||||
CreatedAt *time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
@@ -255,6 +255,7 @@ type WikiContent struct {
|
||||
WikiID pgtype.UUID `json:"wiki_id"`
|
||||
Title string `json:"title"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
Preview pgtype.Text `json:"preview"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
@@ -104,17 +104,18 @@ func (q *Queries) CreateWiki(ctx context.Context, arg CreateWikiParams) (Wiki, e
|
||||
|
||||
const createWikiContent = `-- name: CreateWikiContent :one
|
||||
INSERT INTO wiki_content (
|
||||
id, wiki_id, title, content
|
||||
id, wiki_id, title, content, preview
|
||||
) VALUES (
|
||||
COALESCE($4::uuid, uuidv7()), $1, $2, $3
|
||||
COALESCE($5::uuid, uuidv7()), $1, $2, $3, $4
|
||||
)
|
||||
RETURNING id, wiki_id, title, content, is_deleted, created_at
|
||||
RETURNING id, wiki_id, title, content, preview, is_deleted, created_at
|
||||
`
|
||||
|
||||
type CreateWikiContentParams struct {
|
||||
WikiID pgtype.UUID `json:"wiki_id"`
|
||||
Title string `json:"title"`
|
||||
Content pgtype.Text `json:"content"`
|
||||
Preview pgtype.Text `json:"preview"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
@@ -123,6 +124,7 @@ func (q *Queries) CreateWikiContent(ctx context.Context, arg CreateWikiContentPa
|
||||
arg.WikiID,
|
||||
arg.Title,
|
||||
arg.Content,
|
||||
arg.Preview,
|
||||
arg.ID,
|
||||
)
|
||||
var i WikiContent
|
||||
@@ -131,6 +133,7 @@ func (q *Queries) CreateWikiContent(ctx context.Context, arg CreateWikiContentPa
|
||||
&i.WikiID,
|
||||
&i.Title,
|
||||
&i.Content,
|
||||
&i.Preview,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
@@ -228,7 +231,7 @@ func (q *Queries) GetWikiBySlug(ctx context.Context, slug pgtype.Text) (Wiki, er
|
||||
}
|
||||
|
||||
const getWikiContentByIDs = `-- name: GetWikiContentByIDs :many
|
||||
SELECT id, wiki_id, title, content, is_deleted, created_at
|
||||
SELECT id, wiki_id, title, content, preview, is_deleted, created_at
|
||||
FROM wiki_content
|
||||
WHERE id = ANY($1::uuid[]) AND is_deleted = false
|
||||
`
|
||||
@@ -247,6 +250,7 @@ func (q *Queries) GetWikiContentByIDs(ctx context.Context, dollar_1 []pgtype.UUI
|
||||
&i.WikiID,
|
||||
&i.Title,
|
||||
&i.Content,
|
||||
&i.Preview,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
@@ -261,7 +265,7 @@ func (q *Queries) GetWikiContentByIDs(ctx context.Context, dollar_1 []pgtype.UUI
|
||||
}
|
||||
|
||||
const getWikiContentById = `-- name: GetWikiContentById :one
|
||||
SELECT id, wiki_id, title, content, is_deleted, created_at
|
||||
SELECT id, wiki_id, title, content, preview, is_deleted, created_at
|
||||
FROM wiki_content
|
||||
WHERE id = $1 AND is_deleted = false
|
||||
`
|
||||
@@ -274,6 +278,7 @@ func (q *Queries) GetWikiContentById(ctx context.Context, id pgtype.UUID) (WikiC
|
||||
&i.WikiID,
|
||||
&i.Title,
|
||||
&i.Content,
|
||||
&i.Preview,
|
||||
&i.IsDeleted,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
|
||||
@@ -67,6 +67,7 @@ type WikiContentEntity struct {
|
||||
WikiID string `json:"wiki_id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Preview string `json:"preview"`
|
||||
IsDeleted bool `json:"is_deleted"`
|
||||
CreatedAt *time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
@@ -533,6 +533,7 @@ func (r *wikiRepository) CreateContent(ctx context.Context, params sqlc.CreateWi
|
||||
WikiID: convert.UUIDToString(row.WikiID),
|
||||
Title: row.Title,
|
||||
Content: convert.TextToString(row.Content),
|
||||
Preview: convert.TextToString(row.Preview),
|
||||
IsDeleted: row.IsDeleted,
|
||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||
}, nil
|
||||
@@ -576,6 +577,7 @@ func (r *wikiRepository) getContentByIDsWithFallback(ctx context.Context, ids []
|
||||
WikiID: convert.UUIDToString(row.WikiID),
|
||||
Title: row.Title,
|
||||
Content: convert.TextToString(row.Content),
|
||||
Preview: convert.TextToString(row.Preview),
|
||||
IsDeleted: row.IsDeleted,
|
||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||
}
|
||||
@@ -624,6 +626,7 @@ func (r *wikiRepository) GetContentByID(ctx context.Context, id pgtype.UUID) (*m
|
||||
WikiID: convert.UUIDToString(row.WikiID),
|
||||
Title: row.Title,
|
||||
Content: convert.TextToString(row.Content),
|
||||
Preview: convert.TextToString(row.Preview),
|
||||
IsDeleted: row.IsDeleted,
|
||||
CreatedAt: convert.TimeToPtr(row.CreatedAt),
|
||||
}
|
||||
|
||||
@@ -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