- 编辑器投稿页布局优化:标题与编辑器高度动态适配,工具栏与内容区视觉对齐 - 稿件展示页布局优化:MD 渲染区与评论区视觉分离,代码块主题微调 - CSRF 中间件:图像上传端点豁免,解决 Vditor 拖拽/粘贴上传 403 - Post 状态映射、GetGinUser、SaveUploadedFile 提取至 common 包,遵循审计建议 - 新增个人空间功能:/space(需登录)重定向到 /space/:uid,/space/:uid 公开访问 - 空间页模板:参考 B 站布局,展示头像、用户名、个性签名、UID、加入时间及稿件列表 - 导航栏:用户名链接指向 /space,新增「设置」入口 - 分层实现:SpaceController → SpaceService → PostRepo.FindByUserID,严格 ISP 接口隔离
37 lines
1.4 KiB
Go
37 lines
1.4 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"`
|
|
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"
|
|
)
|