first commit
This commit is contained in:
30
internal/models/post_category.go
Normal file
30
internal/models/post_category.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// PostCategory represents a blog post category with optional parent-child hierarchy.
|
||||
type PostCategory struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primaryKey" json:"id"`
|
||||
Title string `gorm:"type:varchar(254);not null" json:"title"`
|
||||
Keywords string `gorm:"type:varchar(254);not null" json:"keywords"`
|
||||
Description string `gorm:"type:varchar(254);not null" json:"description"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||
Order int `gorm:"default:1;index" json:"order"`
|
||||
Slug string `gorm:"type:varchar(250);uniqueIndex:idx_post_category_slug_parent;not null" json:"slug"`
|
||||
ParentID *uuid.UUID `gorm:"uniqueIndex:idx_post_category_slug_parent" json:"parent_id,omitempty"`
|
||||
Parent *PostCategory `gorm:"foreignKey:ParentID" json:"parent,omitempty"`
|
||||
Children []PostCategory `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
||||
Image string `gorm:"type:text" json:"image,omitempty"`
|
||||
Posts []Post `gorm:"many2many:post_post_categories;" json:"posts,omitempty"`
|
||||
}
|
||||
|
||||
// TableName overrides the table name used by PostCategory.
|
||||
func (PostCategory) TableName() string {
|
||||
return "post_categories"
|
||||
}
|
||||
Reference in New Issue
Block a user