- 评论图片上传(LV4+,经验≥1500),JPEG/PNG 自动转 WebP,二进制搜索质量优化 - 后台评论管理页面,支持关键词搜索、分页、删除,侧边栏新增入口 - 通知跳转高亮:评论通知 RelatedID 改为 postID,消息页链接到 #comments,前端自动滚动 - 新增 adminCommentUseCase/commentStore 接口(遵循 ISP),AdminCommentRow 移至 model 层 - 前端 @mention 联想/图片上传光标插入/评论展开收起/内联回复交互完善
55 lines
2.5 KiB
Go
55 lines
2.5 KiB
Go
package model
|
||
|
||
import "time"
|
||
|
||
// Comment 评论模型
|
||
type Comment struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
PostID uint `gorm:"index;not null" json:"post_id"`
|
||
RootID uint `gorm:"index;not null" json:"root_id"` // 根评论ID,顶级评论指向自身
|
||
ParentID *uint `gorm:"index" json:"parent_id"` // 父评论ID,NULL=顶级评论
|
||
ReplyToUID string `gorm:"type:varchar(36);default:''" json:"reply_to_uid"` // 被回复者UID
|
||
Body string `gorm:"type:text;not null" json:"body"` // 评论内容(纯文本 + 图片URL)
|
||
IsDeleted bool `gorm:"default:false;index" json:"is_deleted"`
|
||
LikesCount int `gorm:"default:0" json:"likes_count"`
|
||
DislikesCount int `gorm:"default:0" json:"dislikes_count"` // 仅后台可见
|
||
UserID uint `gorm:"index;not null" json:"user_id"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
|
||
// 非数据库字段(联表查询填充)
|
||
AuthorName string `gorm:"-:migration;<-:false;column:author_name" json:"author_name,omitempty"`
|
||
AuthorAvatar string `gorm:"-:migration;<-:false;column:author_avatar" json:"author_avatar,omitempty"`
|
||
AuthorLevel int `gorm:"-:migration;<-:false;column:author_level" json:"author_level,omitempty"`
|
||
// ReplyToName 被回复者当前显示名(JOIN users 获取,动态解析,改名后自动更新)
|
||
ReplyToName string `gorm:"-:migration;<-:false" json:"reply_to_name,omitempty"`
|
||
// RepliesCount 回复数(非DB字段,查询填充)
|
||
RepliesCount int `gorm:"-:migration;<-:false" json:"replies_count,omitempty"`
|
||
}
|
||
|
||
// CommentMention @提及映射(绑定UID,不是username,支持改名后自动更新显示名)
|
||
type CommentMention struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
CommentID uint `gorm:"uniqueIndex:idx_comment_uid,priority:1;not null" json:"comment_id"`
|
||
UID string `gorm:"type:varchar(36);uniqueIndex:idx_comment_uid,priority:2;not null" json:"uid"`
|
||
}
|
||
|
||
// UserSearchResult @搜索用户结果
|
||
type UserSearchResult struct {
|
||
UID string `json:"uid"`
|
||
Username string `json:"username"`
|
||
Level int `json:"level"`
|
||
}
|
||
|
||
// AdminCommentRow 后台评论列表行
|
||
type AdminCommentRow struct {
|
||
ID uint `json:"id"`
|
||
PostID uint `json:"post_id"`
|
||
PostTitle string `json:"post_title"`
|
||
Body string `json:"body"`
|
||
AuthorName string `json:"author_name"`
|
||
IsDeleted bool `json:"is_deleted"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
}
|