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:
@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"metazone.cc/mce/internal/common"
|
||||
"metazone.cc/mce/internal/config"
|
||||
@ -189,3 +190,26 @@ func (s *PostService) RecordGuestRead(visitorID string, postID uint) {
|
||||
}
|
||||
_ = s.repo.IncrementViewsCount(postID)
|
||||
}
|
||||
|
||||
// Pin 置顶文章
|
||||
func (s *PostService) Pin(postID uint, pinType string) error {
|
||||
post, err := s.findPost(postID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
now := time.Now()
|
||||
post.PinType = pinType
|
||||
post.PinnedAt = &now
|
||||
return s.repo.Update(post)
|
||||
}
|
||||
|
||||
// Unpin 取消置顶
|
||||
func (s *PostService) Unpin(postID uint) error {
|
||||
post, err := s.findPost(postID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
post.PinType = ""
|
||||
post.PinnedAt = nil
|
||||
return s.repo.Update(post)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user