- 新增 Comment/CommentMention 模型,Post 新增 CommentsCount 冗余计数器 - 新增 CommentRepo(CRUD + @搜索 LV3+ + 回复统计 + 文章作者查询) - 新增 CommentService(发表/回复/删除/@解析/通知 NotifyComment/NotifyCommentReply) - 新增 CommentController(6 个 API 端点),commentUseCase ISP 接口 - 新增评论路由(公开读取 + 需登录写入),依赖注入,错误哨兵,数据库迁移 - 前端评论区 HTML/CSS/JS:分页加载、回复折叠展开、内联回复表单、@提及自动补全
43 lines
2.0 KiB
Go
43 lines
2.0 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// Post 帖子/文章模型
|
||
type Post struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
Title string `gorm:"type:varchar(200);not null" json:"title"`
|
||
Body string `gorm:"type:text" json:"body"` // Markdown content
|
||
Excerpt string `gorm:"type:varchar(500)" json:"excerpt"` // plain text summary for list
|
||
UserID uint `gorm:"index;not null" json:"user_id"`
|
||
Status string `gorm:"type:varchar(20);index;default:draft;not null" json:"status"`
|
||
IsLocked bool `gorm:"default:false" json:"is_locked"`
|
||
LockReason string `gorm:"type:varchar(500);default:''" json:"lock_reason,omitempty"`
|
||
PendingTitle string `gorm:"type:varchar(200);default:''" json:"pending_title,omitempty"`
|
||
PendingBody string `gorm:"type:text" json:"pending_body,omitempty"`
|
||
RejectReason string `gorm:"type:varchar(500);default:''" json:"reject_reason,omitempty"`
|
||
AllowComment bool `gorm:"default:true" json:"allow_comment"`
|
||
CommentsCount int `gorm:"default:0" json:"comments_count"` // 评论数(冗余计数器)
|
||
TotalEnergyReceived int `gorm:"default:0" json:"total_energy_received"` // 文章累计被赋能域能(乘10,冗余计数)
|
||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
|
||
// 非数据库字段(联表查询填充)
|
||
// gorm:"-:migration" 指定不创建/迁移该列,"<-:false" 禁止写入,"column:author_name" 允许
|
||
// 从 JOIN 查询的 users.username AS author_name 别名中读取
|
||
AuthorName string `gorm:"-:migration;<-:false;column:author_name" json:"author_name,omitempty"`
|
||
}
|
||
|
||
// 帖子状态常量
|
||
const (
|
||
PostStatusDraft = "draft"
|
||
PostStatusPending = "pending"
|
||
PostStatusApproved = "approved"
|
||
PostStatusRejected = "rejected"
|
||
PostStatusLocked = "locked"
|
||
)
|