feat: 添加内容置顶功能,更新相关数据模型和前端视图
This commit is contained in:
@@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
@@ -129,6 +130,7 @@ func (s *creator) ListContents(
|
||||
}
|
||||
}
|
||||
if filter.Key != nil && *filter.Key != "" {
|
||||
fmt.Printf("DEBUG: Filter Key: '%s'\n", *filter.Key)
|
||||
q = q.Where(tbl.Key.Eq(*filter.Key))
|
||||
}
|
||||
if filter.Keyword != nil && *filter.Keyword != "" {
|
||||
@@ -205,6 +207,7 @@ func (s *creator) ListContents(
|
||||
VideoCount: videoCount,
|
||||
AudioCount: audioCount,
|
||||
Status: string(item.Status),
|
||||
IsPinned: item.IsPinned,
|
||||
IsPurchased: false,
|
||||
})
|
||||
}
|
||||
@@ -311,11 +314,48 @@ func (s *creator) UpdateContent(
|
||||
if form.Status != "" {
|
||||
contentUpdates.Status = consts.ContentStatus(form.Status)
|
||||
}
|
||||
|
||||
// Determine final status
|
||||
finalStatus := c.Status
|
||||
if form.Status != "" {
|
||||
finalStatus = consts.ContentStatus(form.Status)
|
||||
}
|
||||
|
||||
// Validation: Only published content can be pinned
|
||||
if form.IsPinned != nil && *form.IsPinned && finalStatus != consts.ContentStatusPublished {
|
||||
return errorx.ErrBadRequest.WithMsg("只有已发布的内容支持置顶")
|
||||
}
|
||||
|
||||
// Perform standard updates
|
||||
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(contentUpdates)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Handle IsPinned Logic
|
||||
if finalStatus != consts.ContentStatusPublished {
|
||||
// Force Unpin if not published
|
||||
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.IsPinned.Value(false))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if form.IsPinned != nil {
|
||||
// Explicit Pin Update requested
|
||||
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.IsPinned.Value(*form.IsPinned))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If setting to true, unpin others
|
||||
if *form.IsPinned {
|
||||
if _, err := tx.Content.WithContext(ctx).
|
||||
Where(tx.Content.TenantID.Eq(tid), tx.Content.ID.Neq(cid)).
|
||||
UpdateSimple(tx.Content.IsPinned.Value(false)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Update Price
|
||||
// Check if price exists
|
||||
if form.Price != nil {
|
||||
|
||||
Reference in New Issue
Block a user