add like functionality with Like model, implement like/unlike methods, and update Post and Comment models to track like counts

This commit is contained in:
2025-07-22 22:45:55 +08:00
parent cbe73121f2
commit 562b9bd17f
15 changed files with 216 additions and 33 deletions

View File

@ -4,9 +4,13 @@ import "gorm.io/gorm"
type Post struct {
gorm.Model
UserID uint `gorm:"index"` // 发布者的用户ID
User User `gorm:"foreignKey:UserID;references:ID"` // 关联的用户
Title string `gorm:"type:text;not null"` // 帖子标题
Content string `gorm:"type:text;not null"` // 帖子内容
Labels []Label `gorm:"many2many:post_labels;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` // 关联的标签
UserID uint `gorm:"index"` // 发布者的用户ID
User User `gorm:"foreignKey:UserID;references:ID"` // 关联的用户
Title string `gorm:"type:text;not null"` // 帖子标题
Content string `gorm:"type:text;not null"` // 帖子内容
Labels []Label `gorm:"many2many:post_labels;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` // 关联的标签
IsPrivate bool `gorm:"default:false"` // 是否为私密帖子
LikeCount uint64
CommentCount uint64
VisitorCount uint64
}