feat: 文章属性 — Post Model 扩展 + 置顶系统

- Post 新增 7 字段:Visibility/PostType/ReprintSource/Declaration/ReprintProhibited/PinType/PinnedAt
- 公开列表过滤 private 文章(管理员可见全部)
- 列表排序:全局置顶 > 按时间
- declarationLabel 模板函数(7 种创作声明)
- Pin/Unpin API(admin+,category/global 两种置顶类型)
This commit is contained in:
2026-06-22 00:04:55 +08:00
parent fc57ed17d4
commit 9c452afb40
8 changed files with 127 additions and 8 deletions

View File

@ -103,6 +103,44 @@ func (ctrl *AdminPostController) Unlock(c *gin.Context) {
common.OkMessage(c, "已解锁")
}
// Pin 置顶文章
func (ctrl *AdminPostController) Pin(c *gin.Context) {
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
if err != nil {
common.Error(c, http.StatusBadRequest, "无效的帖子 ID")
return
}
var req struct {
PinType string `json:"pin_type" binding:"required"`
}
if err := c.ShouldBindJSON(&req); err != nil || (req.PinType != model.PinTypeCategory && req.PinType != model.PinTypeGlobal) {
common.Error(c, http.StatusBadRequest, "无效的置顶类型")
return
}
if err := ctrl.postService.Pin(uint(id), req.PinType); err != nil {
common.Error(c, http.StatusInternalServerError, "置顶失败")
return
}
common.OkMessage(c, "已置顶")
}
// Unpin 取消置顶
func (ctrl *AdminPostController) Unpin(c *gin.Context) {
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
if err != nil {
common.Error(c, http.StatusBadRequest, "无效的帖子 ID")
return
}
if err := ctrl.postService.Unpin(uint(id)); err != nil {
common.Error(c, http.StatusInternalServerError, "取消置顶失败")
return
}
common.OkMessage(c, "已取消置顶")
}
// Restore 恢复软删除
func (ctrl *AdminPostController) Restore(c *gin.Context) {
id, err := strconv.ParseUint(c.Param("id"), 10, 64)

View File

@ -36,7 +36,7 @@ type auditStatusProvider interface {
FindByID(id uint) (*model.User, error)
}
// adminPostUseCase AdminPostController 对 PostService 的最小依赖ISP7 个方法)
// adminPostUseCase AdminPostController 对 PostService 的最小依赖ISP9 个方法)
type adminPostUseCase interface {
ListAdmin(keyword, status string, page, pageSize int) ([]model.Post, int64, error)
ListPendingRevisions(keyword string, page, pageSize int) ([]model.Post, int64, error)
@ -44,6 +44,8 @@ type adminPostUseCase interface {
Reject(postID uint, reason string) error
Lock(postID uint, reason string) error
Unlock(postID uint) error
Pin(postID uint, pinType string) error
Unpin(postID uint) error
Restore(postID uint) error
}