feat(article): support regenerating failed articles
This commit is contained in:
@@ -51,7 +51,25 @@ func (r *articleRepository) CreateArticle(ctx context.Context, input CreateArtic
|
||||
})
|
||||
}
|
||||
|
||||
func NextArticleVersionNo(ctx context.Context, db generated.DBTX, articleID int64) (int, error) {
|
||||
var nextVersionNo int
|
||||
err := db.QueryRow(ctx, `
|
||||
SELECT COALESCE(MAX(version_no), 0) + 1
|
||||
FROM article_versions
|
||||
WHERE article_id = $1
|
||||
`, articleID).Scan(&nextVersionNo)
|
||||
return nextVersionNo, err
|
||||
}
|
||||
|
||||
func (r *articleRepository) CreateArticleVersion(ctx context.Context, input CreateArticleVersionInput) (int64, error) {
|
||||
if input.VersionNo <= 0 {
|
||||
nextVersionNo, err := NextArticleVersionNo(ctx, r.db, input.ArticleID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
input.VersionNo = nextVersionNo
|
||||
}
|
||||
|
||||
previous, err := loadLatestArticleVersionContent(ctx, r.db, input.ArticleID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
Reference in New Issue
Block a user