feat: 更新内容创建和更新表单,支持封面ID和媒体ID字段
This commit is contained in:
@@ -30,6 +30,7 @@ type ContentCreateForm struct {
|
||||
Genre string `json:"genre"`
|
||||
Key string `json:"key"`
|
||||
Price float64 `json:"price"`
|
||||
CoverIDs []string `json:"cover_ids"`
|
||||
MediaIDs []string `json:"media_ids"`
|
||||
}
|
||||
|
||||
@@ -38,6 +39,7 @@ type ContentUpdateForm struct {
|
||||
Genre string `json:"genre"`
|
||||
Key string `json:"key"`
|
||||
Price float64 `json:"price"`
|
||||
CoverIDs []string `json:"cover_ids"`
|
||||
MediaIDs []string `json:"media_ids"`
|
||||
}
|
||||
|
||||
|
||||
@@ -173,18 +173,30 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
|
||||
}
|
||||
|
||||
// 2. Link Assets
|
||||
if len(form.MediaIDs) > 0 {
|
||||
var assets []*models.ContentAsset
|
||||
for i, mid := range form.MediaIDs {
|
||||
assets = append(assets, &models.ContentAsset{
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: content.ID,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleMain,
|
||||
})
|
||||
}
|
||||
var assets []*models.ContentAsset
|
||||
// Covers
|
||||
for i, mid := range form.CoverIDs {
|
||||
assets = append(assets, &models.ContentAsset{
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: content.ID,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleCover,
|
||||
})
|
||||
}
|
||||
// Main Media
|
||||
for i, mid := range form.MediaIDs {
|
||||
assets = append(assets, &models.ContentAsset{
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: content.ID,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleMain,
|
||||
})
|
||||
}
|
||||
if len(assets) > 0 {
|
||||
if err := tx.ContentAsset.WithContext(ctx).Create(assets...); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -258,23 +270,35 @@ func (s *creator) UpdateContent(
|
||||
}
|
||||
|
||||
// 4. Update Assets (Full replacement strategy)
|
||||
if len(form.MediaIDs) > 0 {
|
||||
_, err = tx.ContentAsset.WithContext(ctx).Where(tx.ContentAsset.ContentID.Eq(cid)).Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.ContentAsset.WithContext(ctx).Where(tx.ContentAsset.ContentID.Eq(cid)).Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var assets []*models.ContentAsset
|
||||
for i, mid := range form.MediaIDs {
|
||||
assets = append(assets, &models.ContentAsset{
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: cid,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleMain, // Default to main
|
||||
})
|
||||
}
|
||||
var assets []*models.ContentAsset
|
||||
// Covers
|
||||
for i, mid := range form.CoverIDs {
|
||||
assets = append(assets, &models.ContentAsset{
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: cid,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleCover,
|
||||
})
|
||||
}
|
||||
// Main Media
|
||||
for i, mid := range form.MediaIDs {
|
||||
assets = append(assets, &models.ContentAsset{
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: cid,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleMain,
|
||||
})
|
||||
}
|
||||
if len(assets) > 0 {
|
||||
if err := tx.ContentAsset.WithContext(ctx).Create(assets...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -138,4 +138,4 @@ LocalPath = "./storage"
|
||||
# 签名密钥
|
||||
Secret = "your-storage-secret"
|
||||
# 公共访问URL前缀
|
||||
BaseURL = "http://localhost:8080/v1/storage"
|
||||
BaseURL = "/v1/storage"
|
||||
|
||||
Reference in New Issue
Block a user