Files
sm-journal-plugin/models/category.go
Jakub Zych 740dcd086d feat(api): serve the category content field on GET /_journal/api/v1/categories
- add the nullable TEXT column golem15_journal_categories.content (migration 202610090001)
- map it as models.Category.Content and emit category content on every categories row
- document the categories row shape and the stored-as-is HTML semantics
2026-10-09 16:24:20 +02:00

45 lines
1.5 KiB
Go

package models
import "time"
// Category is a journal category stored on golem15_journal_categories.
type Category struct {
ID uint `gorm:"column:id;primaryKey"`
Name string `gorm:"column:name"`
Slug string `gorm:"column:slug"`
Code *string `gorm:"column:code"`
Description *string `gorm:"column:description"`
Content *string `gorm:"column:content"` // HTML body (D-21): stored and served as is, not translatable
ParentID *uint `gorm:"column:parent_id"`
NestLeft *int `gorm:"column:nest_left"`
NestRight *int `gorm:"column:nest_right"`
NestDepth *int `gorm:"column:nest_depth"`
CreatedAt *time.Time `gorm:"column:created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at"`
}
func (Category) TableName() string { return "golem15_journal_categories" }
// MorphName is the PHP class string stored on translate attributes.
func (Category) MorphName() string { return `Golem15\Journal\Models\Category` }
func (Category) Translatable() []string { return []string{"name", "description", "slug"} }
func (Category) TranslatableIndexes() []string { return []string{"slug"} }
// Fillable is JOURNAL-002: nest_* stay out of mass assignment.
func (Category) Fillable() []string {
return []string{"name", "slug", "code", "description", "parent_id"}
}
func (Category) Rules() map[string]string {
return map[string]string{
"name": "required",
"slug": "required",
}
}
func init() {
Register(Category{})
}