package model import "gorm.io/datatypes" // Comment 帖子评论 type Comment struct { Base PostID string `gorm:"size:24;index" json:"post_id"` UserID string `gorm:"size:24;index" json:"user_id"` AuthorName string `gorm:"size:64" json:"author_name"` Content string `gorm:"size:512" json:"content"` Images datatypes.JSON `json:"images"` // 两级评论:ParentID 为空是一级评论,否则是某条一级评论下的回复。 // 不做无限层级——手机上层层缩进读到第四层就没法看了, // 主流产品(微信、小红书、B站)都是两级 + @某人 表达指向。 ParentID string `gorm:"size:24;index" json:"parent_id"` ReplyToName string `gorm:"size:64" json:"reply_to_name"` Status string `gorm:"size:16;default:published" json:"status"` IsSelf bool `gorm:"-" json:"is_self"` // 计算字段:是不是我自己发的 Replies []Comment `gorm:"-" json:"replies"` // 计算字段:一级评论下挂的回复 ReplyN int `gorm:"-" json:"reply_n"` // 回复总数(可能多于返回的条数) }