34 lines
1.4 KiB
Go
34 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Post represents a blog post with category and tag relations.
|
|
type Post struct {
|
|
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primaryKey" json:"id"`
|
|
Title string `gorm:"type:varchar(254);not null" json:"title"`
|
|
Content string `gorm:"type:text" json:"content,omitempty"`
|
|
Keywords string `gorm:"type:varchar(254);not null" json:"keywords"`
|
|
Image string `gorm:"type:text" json:"image,omitempty"`
|
|
Video string `gorm:"type:varchar(254);default:'none'" json:"video,omitempty"`
|
|
Slug string `gorm:"type:varchar(250);uniqueIndex;not null" json:"slug"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
IsActive bool `gorm:"default:true" json:"is_active"`
|
|
IsFront bool `gorm:"default:true" json:"is_front"`
|
|
ParentID *uuid.UUID `json:"parent_id,omitempty"`
|
|
Parent *Post `gorm:"foreignKey:ParentID" json:"parent,omitempty"`
|
|
Children []Post `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
|
Categories []PostCategory `gorm:"many2many:post_post_categories;" json:"categories,omitempty"`
|
|
Tags []PostTag `gorm:"many2many:post_post_tags;" json:"tags,omitempty"`
|
|
Comments []PostComment `gorm:"foreignKey:PostID" json:"comments,omitempty"`
|
|
}
|
|
|
|
// TableName overrides the table name used by Post.
|
|
func (Post) TableName() string {
|
|
return "posts"
|
|
}
|