feat: 评论系统补充功能完成——图片上传、后台管理、通知跳转高亮
- 评论图片上传(LV4+,经验≥1500),JPEG/PNG 自动转 WebP,二进制搜索质量优化 - 后台评论管理页面,支持关键词搜索、分页、删除,侧边栏新增入口 - 通知跳转高亮:评论通知 RelatedID 改为 postID,消息页链接到 #comments,前端自动滚动 - 新增 adminCommentUseCase/commentStore 接口(遵循 ISP),AdminCommentRow 移至 model 层 - 前端 @mention 联想/图片上传光标插入/评论展开收起/内联回复交互完善
This commit is contained in:
@ -248,3 +248,31 @@ func (r *CommentRepo) FindPostAuthorID(postID uint) (uint, error) {
|
||||
err := r.db.Table("posts").Select("user_id").Where("id = ?", postID).Scan(&authorID).Error
|
||||
return authorID, err
|
||||
}
|
||||
|
||||
// ListAllComments 后台评论列表(支持关键词搜索、分页)
|
||||
func (r *CommentRepo) ListAllComments(keyword string, showDeleted bool, offset, limit int) ([]model.AdminCommentRow, int64, error) {
|
||||
var total int64
|
||||
q := r.db.Table("comments").
|
||||
Joins("LEFT JOIN users ON users.uid = comments.user_id").
|
||||
Joins("LEFT JOIN posts ON posts.id = comments.post_id")
|
||||
|
||||
if !showDeleted {
|
||||
q = q.Where("comments.is_deleted = false")
|
||||
}
|
||||
if keyword != "" {
|
||||
like := "%" + keyword + "%"
|
||||
q = q.Where("comments.body LIKE ? OR users.username LIKE ? OR posts.title LIKE ?", like, like, like)
|
||||
}
|
||||
|
||||
if err := q.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var rows []model.AdminCommentRow
|
||||
err := q.
|
||||
Select("comments.id, comments.post_id, posts.title as post_title, comments.body, users.username as author_name, comments.is_deleted, comments.created_at, comments.updated_at").
|
||||
Order("comments.created_at DESC").
|
||||
Offset(offset).Limit(limit).
|
||||
Scan(&rows).Error
|
||||
return rows, total, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user