feat: 分类系统 + 标签系统 — Phase 4 完成
分类:Model/Repo/Service/Controller + 管理后台树形页面 + 首页导航栏
标签:Model/Repo/Service/Controller + /tags/{slug} 落地页 + 写文章页输入
Post 加 CategoryID,Create/Update 支持分类和标签
SQL 迁移含 categories/tags/post_tags 表及预设未分类
This commit is contained in:
18
internal/model/category.go
Normal file
18
internal/model/category.go
Normal file
@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Category 文章分类(两级树形结构)
|
||||
type Category struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"type:varchar(50);not null" json:"name"`
|
||||
Slug string `gorm:"type:varchar(50);not null;uniqueIndex" json:"slug"`
|
||||
Description string `gorm:"type:varchar(200);default:''" json:"description,omitempty"`
|
||||
ParentID *uint `gorm:"index" json:"parent_id,omitempty"`
|
||||
Sort int `gorm:"default:0" json:"sort"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 非 DB 字段(树形填充)
|
||||
Children []Category `gorm:"-" json:"children,omitempty"`
|
||||
}
|
||||
@ -39,6 +39,8 @@ type PostCreateRequest struct {
|
||||
ReprintSource string `json:"reprint_source"`
|
||||
Declaration string `json:"declaration"`
|
||||
ReprintProhibited bool `json:"reprint_prohibited"`
|
||||
CategoryID string `json:"category_id"`
|
||||
Tags string `json:"tags"`
|
||||
}
|
||||
|
||||
// PostUpdateRequest 编辑请求
|
||||
@ -50,6 +52,8 @@ type PostUpdateRequest struct {
|
||||
ReprintSource string `json:"reprint_source"`
|
||||
Declaration string `json:"declaration"`
|
||||
ReprintProhibited bool `json:"reprint_prohibited"`
|
||||
CategoryID string `json:"category_id"`
|
||||
Tags string `json:"tags"`
|
||||
}
|
||||
|
||||
// PostRejectRequest 退回请求
|
||||
|
||||
@ -21,6 +21,7 @@ type Post struct {
|
||||
RejectReason string `gorm:"type:varchar(500);default:''" json:"reject_reason,omitempty"`
|
||||
|
||||
// 文章属性
|
||||
CategoryID *uint `gorm:"index" json:"category_id,omitempty"` // 二级分类 ID
|
||||
Visibility string `gorm:"type:varchar(10);default:public" json:"visibility"` // public / private
|
||||
PostType string `gorm:"type:varchar(10);default:original" json:"post_type"` // original / reprint
|
||||
ReprintSource string `gorm:"type:varchar(500);default:''" json:"reprint_source,omitempty"` // 转载来源
|
||||
|
||||
17
internal/model/tag.go
Normal file
17
internal/model/tag.go
Normal file
@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Tag 标签
|
||||
type Tag struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
Name string `gorm:"type:varchar(50);not null" json:"name"`
|
||||
Slug string `gorm:"type:varchar(50);not null;uniqueIndex" json:"slug"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// PostTag 文章-标签关联
|
||||
type PostTag struct {
|
||||
PostID uint `gorm:"primarykey" json:"post_id"`
|
||||
TagID uint `gorm:"primarykey" json:"tag_id"`
|
||||
}
|
||||
Reference in New Issue
Block a user