feat: implement article version content storage and reconstruction logic; enhance article repository with version management
This commit is contained in:
@@ -30,11 +30,12 @@ type ArticleRepository interface {
|
||||
}
|
||||
|
||||
type articleRepository struct {
|
||||
q generated.Querier
|
||||
db generated.DBTX
|
||||
q generated.Querier
|
||||
}
|
||||
|
||||
func NewArticleRepository(db generated.DBTX) ArticleRepository {
|
||||
return &articleRepository{q: newQuerier(db)}
|
||||
return &articleRepository{db: db, q: newQuerier(db)}
|
||||
}
|
||||
|
||||
func (r *articleRepository) CreateArticle(ctx context.Context, input CreateArticleInput) (int64, error) {
|
||||
@@ -46,15 +47,42 @@ func (r *articleRepository) CreateArticle(ctx context.Context, input CreateArtic
|
||||
}
|
||||
|
||||
func (r *articleRepository) CreateArticleVersion(ctx context.Context, input CreateArticleVersionInput) (int64, error) {
|
||||
return r.q.CreateArticleVersion(ctx, generated.CreateArticleVersionParams{
|
||||
ArticleID: input.ArticleID,
|
||||
VersionNo: int32(input.VersionNo),
|
||||
Title: pgText(&input.Title),
|
||||
HtmlContent: pgText(&input.HTMLContent),
|
||||
MarkdownContent: pgText(&input.MarkdownContent),
|
||||
WordCount: int32(input.WordCount),
|
||||
SourceLabel: pgText(&input.SourceLabel),
|
||||
previous, err := loadLatestArticleVersionContent(ctx, r.db, input.ArticleID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
storedHTML, storedMarkdown := buildArticleVersionDiffStorage(*previous, ArticleVersionContent{
|
||||
HTMLContent: stringPtr(input.HTMLContent),
|
||||
MarkdownContent: stringPtr(input.MarkdownContent),
|
||||
})
|
||||
|
||||
var versionID int64
|
||||
err = r.db.QueryRow(ctx, `
|
||||
INSERT INTO article_versions (
|
||||
article_id,
|
||||
version_no,
|
||||
title,
|
||||
html_content,
|
||||
markdown_content,
|
||||
word_count,
|
||||
source_label
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id
|
||||
`,
|
||||
input.ArticleID,
|
||||
input.VersionNo,
|
||||
pgText(&input.Title),
|
||||
pgText(storedHTML),
|
||||
pgText(storedMarkdown),
|
||||
input.WordCount,
|
||||
pgText(&input.SourceLabel),
|
||||
).Scan(&versionID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return versionID, nil
|
||||
}
|
||||
|
||||
func (r *articleRepository) UpdateArticleCurrentVersion(ctx context.Context, articleID, tenantID, versionID int64) error {
|
||||
|
||||
Reference in New Issue
Block a user