refactor: 统一 BaseModel 嵌入,修复 primaryKey 大小写不一致
Some checks failed
CI / Lint + Build (push) Has been cancelled
Some checks failed
CI / Lint + Build (push) Has been cancelled
变更模型: - Post: 嵌入 BaseModel,移除手动 ID/CreatedAt/UpdatedAt/DeletedAt - Comment: 嵌入 BaseModel,保留 is_deleted 自定义软删除 - Announcement: 嵌入 BaseModel - Category: 嵌入 BaseModel - Folder + FolderItem: 嵌入 BaseModel - CommunityFund: primaryKey → primarykey (统一小写)
This commit is contained in:
@ -4,18 +4,17 @@ 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 uint `gorm:"default:0" 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"`
|
||||
BaseModel
|
||||
|
||||
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 uint `gorm:"default:0" 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"`
|
||||
|
||||
// 非数据库字段(联表查询填充)
|
||||
AuthorName string `gorm:"-:migration;<-:false;column:author_name" json:"author_name,omitempty"`
|
||||
@ -26,7 +25,6 @@ type Comment struct {
|
||||
// RepliesCount 回复数(非DB字段,查询填充)
|
||||
RepliesCount int `gorm:"-:migration;<-:false" json:"replies_count,omitempty"`
|
||||
// Mentions 有效@提及映射 original_username -> {uid, 当前显示名}(非DB字段,批量查询填充)
|
||||
// key=创建时的原始@用户名,value={uid,当前显示名},用户改名后链接仍有效且显示新名
|
||||
Mentions map[string]MentionInfo `gorm:"-" json:"mentions,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user