39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Article status constants.
|
|
const (
|
|
ArticleDraft = 0 // 草稿
|
|
ArticlePublished = 1 // 已发布
|
|
ArticleArchived = 2 // 已归档
|
|
)
|
|
|
|
// Article represents a blog post.
|
|
type Article struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"uniqueIndex:idx_slug_deleted_at" json:"deleted_at"`
|
|
AuthorID uint `gorm:"not null;index" json:"author_id"`
|
|
Title string `gorm:"not null;size:255" json:"title"`
|
|
Summary string `gorm:"size:512" json:"summary"`
|
|
Content string `gorm:"type:text;not null" json:"content"`
|
|
Cover string `gorm:"size:512" json:"cover"`
|
|
Status int `gorm:"default:0;index" json:"status"`
|
|
IsTop bool `gorm:"default:false" json:"is_top"`
|
|
ViewCount int `gorm:"default:0" json:"view_count"`
|
|
Slug string `gorm:"uniqueIndex:idx_slug_deleted_at;size:255" json:"slug"`
|
|
PublishedAt *time.Time `gorm:"index" json:"published_at"`
|
|
Author User `gorm:"foreignKey:AuthorID" json:"-"`
|
|
}
|
|
|
|
// TableName overrides the default GORM table name.
|
|
func (Article) TableName() string {
|
|
return "articles"
|
|
}
|