feat: 添加媒体资源软删除API接口及相关文档
This commit is contained in:
@@ -187,6 +187,34 @@ func (s *content) AttachAsset(ctx context.Context, tenantID, userID, contentID,
|
||||
"sort": sort,
|
||||
}).Info("services.content.attach_asset")
|
||||
|
||||
// 约束:只能绑定本租户内、且已处理完成(ready)的资源;避免未完成处理的资源对外可见。
|
||||
tblContent, queryContent := models.ContentQuery.QueryContext(ctx)
|
||||
if _, err := queryContent.Where(
|
||||
tblContent.TenantID.Eq(tenantID),
|
||||
tblContent.ID.Eq(contentID),
|
||||
).First(); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.ErrRecordNotFound.WithMsg("content not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tblAsset, queryAsset := models.MediaAssetQuery.QueryContext(ctx)
|
||||
asset, err := queryAsset.Where(
|
||||
tblAsset.TenantID.Eq(tenantID),
|
||||
tblAsset.ID.Eq(assetID),
|
||||
tblAsset.DeletedAt.IsNull(),
|
||||
).First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.ErrRecordNotFound.WithMsg("media asset not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if asset.Status != consts.MediaAssetStatusReady {
|
||||
return nil, errorx.ErrPreconditionFailed.WithMsg("media asset not ready")
|
||||
}
|
||||
|
||||
m := &models.ContentAsset{
|
||||
TenantID: tenantID,
|
||||
UserID: userID,
|
||||
|
||||
Reference in New Issue
Block a user