feat: 添加内容创建表单状态字段,优化内容保存和发布逻辑

This commit is contained in:
2026-01-04 21:45:42 +08:00
parent 4b32e64d35
commit 113f9c8d3c
3 changed files with 20 additions and 11 deletions

View File

@@ -30,6 +30,7 @@ type ContentCreateForm struct {
Genre string `json:"genre"`
Key string `json:"key"`
Price float64 `json:"price"`
Status string `json:"status"`
CoverIDs []string `json:"cover_ids"`
MediaIDs []string `json:"media_ids"`
}

View File

@@ -201,6 +201,10 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
uid := userID
return models.Q.Transaction(func(tx *models.Query) error {
status := consts.ContentStatusPublished
if form.Status != "" {
status = consts.ContentStatus(form.Status)
}
// 1. Create Content
content := &models.Content{
TenantID: tid,
@@ -208,7 +212,7 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
Title: form.Title,
Genre: form.Genre,
Key: form.Key,
Status: consts.ContentStatusPublished,
Status: status,
}
if err := tx.Content.WithContext(ctx).Create(content); err != nil {
return err