feat: 实现评论系统(后端 + 前端)

- 新增 Comment/CommentMention 模型,Post 新增 CommentsCount 冗余计数器
- 新增 CommentRepo(CRUD + @搜索 LV3+ + 回复统计 + 文章作者查询)
- 新增 CommentService(发表/回复/删除/@解析/通知 NotifyComment/NotifyCommentReply)
- 新增 CommentController(6 个 API 端点),commentUseCase ISP 接口
- 新增评论路由(公开读取 + 需登录写入),依赖注入,错误哨兵,数据库迁移
- 前端评论区 HTML/CSS/JS:分页加载、回复折叠展开、内联回复表单、@提及自动补全
This commit is contained in:
2026-06-01 13:24:16 +08:00
parent b44d7ca5c3
commit b7acc91f8c
15 changed files with 1416 additions and 7 deletions

View File

@ -115,3 +115,28 @@ type energyStore = EnergyStore
type energyNotifier interface {
Create(userID uint, notifyType, title, content string, relatedID *uint) error
}
// commentStore CommentService 所需的最小仓储接口ISP
type commentStore interface {
Create(comment *model.Comment) error
UpdateRootID(id, rootID uint) error
FindByID(id uint) (*model.Comment, error)
FindRootComments(postID uint, offset, limit int) ([]model.Comment, int64, error)
FindReplies(rootID uint) ([]model.Comment, error)
SoftDelete(id uint) error
IncrCommentsCount(postID uint) error
DecrCommentsCount(postID uint) error
CreateMention(mention *model.CommentMention) error
FindPostIDByComment(commentID uint) (uint, error)
FindPostAuthorID(postID uint) (uint, error)
SearchUsersByLevel(keyword string, minLevel, limit int) ([]struct {
UID string
Username string
}, error)
GetUserUIDByID(userID uint) (string, error)
}
// commentNotifier CommentService 所需的通知接口ISP
type commentNotifier interface {
Create(userID uint, notifyType, title, content string, relatedID *uint) error
}