- Post 模型新增 PendingTitle/PendingBody 字段,分离已发布内容与待审修订 - Update: approved 帖子编辑写入 Pending 字段,不覆盖正文,不改变发布状态 - Approve: 有 PendingBody 时复制到正式字段后清空,无 PendingBody 走首次审核 - Reject: 有 PendingBody 时仅清空待审修订(保持已发布),无 PendingBody 走普通退回 - 新增 ListPendingRevisions 查询,管理后台独立展示"修订待审核"区域 - 详情页展示"修订审核中"标识,编辑页加载待审内容 - 通过修订后直接覆盖,不保留历史版本
40 lines
1.6 KiB
Go
40 lines
1.6 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"`
|
|
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"`
|
|
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"
|
|
)
|