Files
sm-journal-plugin/models/post.go
Jakub Zych 9ae4b9141e feat(15-01): add journal categories, tags, settings, and author slug
Squash the remaining golem15_journal_* tables plus the backend_users
author slug so a host migrate matches the frozen PHP schema.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-06 18:28:17 +02:00

63 lines
2.1 KiB
Go

package models
import (
"time"
"git.golem15.com/golem15/summercms/modules/cabana"
"git.golem15.com/golem15/summercms/modules/lagoon/attach"
)
// Post is a journal entry stored on golem15_journal_posts.
type Post struct {
ID uint `gorm:"column:id;primaryKey"`
UserID *uint `gorm:"column:user_id"`
RedactorID *uint `gorm:"column:redactor_id"`
Title string `gorm:"column:title"`
Slug string `gorm:"column:slug"`
Excerpt string `gorm:"column:excerpt"`
Content string `gorm:"column:content"`
ContentHTML string `gorm:"column:content_html"`
PublishedAt *time.Time `gorm:"column:published_at"`
Published bool `gorm:"column:published"`
IsPinned bool `gorm:"column:is_pinned"`
Metadata *string `gorm:"column:metadata;type:jsonb"`
Sources *string `gorm:"column:sources;type:jsonb"`
CreatedAt *time.Time `gorm:"column:created_at"`
UpdatedAt *time.Time `gorm:"column:updated_at"`
User *cabana.BackendUser `gorm:"foreignKey:UserID" json:"-"`
Categories []Category `gorm:"many2many:golem15_journal_posts_categories;" json:"-"`
Tags []Tag `gorm:"many2many:golem15_journal_posts_tags;" json:"-"`
}
func (Post) TableName() string { return "golem15_journal_posts" }
// MorphName is the PHP class string stored on translate attributes and system_files.
func (Post) MorphName() string { return `Golem15\Journal\Models\Post` }
func (Post) Translatable() []string {
return []string{"title", "content", "content_html", "excerpt", "metadata", "slug"}
}
func (Post) TranslatableIndexes() []string { return []string{"slug"} }
// Fillable is the tracer allow-list. redactor_id, content_html, and user_id
// are never mass-assigned from a map.
func (Post) Fillable() []string {
return []string{
"title", "slug", "excerpt", "content",
"published", "published_at", "is_pinned", "metadata", "sources",
}
}
func (Post) AttachRelations() []attach.Relation {
return []attach.Relation{
{Name: "featured_images", Many: true, Public: true},
{Name: "content_images", Many: true, Public: true},
}
}
func init() {
Register(Post{})
}