feat: 添加仪表板功能,整合统计数据并优化后台管理界面

This commit is contained in:
2025-09-24 12:09:16 +08:00
parent 2bcaad716d
commit 636b4d5ea0
13 changed files with 430 additions and 220 deletions

View File

@ -6,19 +6,24 @@ import (
"gorm.io/gorm"
)
type PostBase struct {
Title string `gorm:"type:text;not null"`
Cover string `gorm:"type:text"`
Content string `gorm:"type:text;not null"`
Type string `gorm:"type:text;default:markdown"`
CategoryID uint `gorm:"index"`
Category Category `gorm:"foreignKey:CategoryID;references:ID"`
Labels []Label `gorm:"many2many:post_labels;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
IsOriginal bool `gorm:"default:true"`
IsPrivate bool `gorm:"default:false"`
}
type Post struct {
gorm.Model
UserID uint `gorm:"index"` // 发布者的用户ID
User User `gorm:"foreignKey:UserID;references:ID"` // 关联的用户
Title string `gorm:"type:text;not null"` // 帖子标题
Cover string `gorm:"type:text"` // 帖子封面图
Content string `gorm:"type:text;not null"` // 帖子内容
Type string `gorm:"type:text;default:markdown"` // markdown类型支持markdown或html或txt
CategoryID uint `gorm:"index"` // 帖子分类ID
Category Category `gorm:"foreignKey:CategoryID;references:ID"` // 关联的分类
Labels []Label `gorm:"many2many:post_labels;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` // 关联的标签
IsOriginal bool `gorm:"default:true"` // 是否为原创帖子
IsPrivate bool `gorm:"default:false"`
UserID uint `gorm:"index"` // 发布者的用户ID
User User `gorm:"foreignKey:UserID;references:ID"` // 关联的用户
// core fields
PostBase
//
LikeCount uint64
CommentCount uint64
ViewCount uint64
@ -71,3 +76,11 @@ func (p *Post) ToDtoWithShortContent(contentLength int) *dto.PostDto {
}
return dtoPost
}
// Draft 草稿
type Draft struct {
gorm.Model
PostID uint `gorm:"uniqueIndex"` // 关联的文章ID
Post Post `gorm:"foreignKey:PostID;references:ID"`
PostBase
}