54 lines
2.1 KiB
Go
54 lines
2.1 KiB
Go
package models
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Minimal, temiz GORM modelleri
|
|
|
|
type Category struct {
|
|
gorm.Model
|
|
Title string `gorm:"type:varchar(254);not null" json:"title"`
|
|
Slug string `gorm:"type:varchar(254);not null;uniqueIndex" json:"slug"`
|
|
Description string `json:"description,omitempty"`
|
|
ParentID *uint `json:"parent_id,omitempty"`
|
|
Parent *Category `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;foreignKey:ParentID" json:"parent,omitempty"`
|
|
Children []Category `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
|
Posts []Post `gorm:"many2many:post_categories;" json:"posts,omitempty"`
|
|
}
|
|
|
|
type Tag struct {
|
|
gorm.Model
|
|
Name string `gorm:"type:varchar(254);not null" json:"name"`
|
|
Posts []Post `gorm:"many2many:post_tags;" json:"posts,omitempty"`
|
|
}
|
|
|
|
type Post struct {
|
|
gorm.Model
|
|
Title string `gorm:"type:varchar(254);not null" json:"title" form:"title"`
|
|
Images string `gorm:"type:text;not null" json:"images" form:"images"`
|
|
ImagesMid string `gorm:"type:text;not null" json:"images_mid" form:"images_mid"`
|
|
ImagesMin string `gorm:"type:text;not null" json:"images_min" form:"images_min"`
|
|
Width int `gorm:"default:0" json:"width" form:"width"`
|
|
Height int `gorm:"default:0" json:"height" form:"height"`
|
|
Quality int `gorm:"default:0" json:"quality" form:"quality"`
|
|
Format string `gorm:"type:varchar(10)" json:"format" form:"format" default:"avif"`
|
|
Content string `gorm:"type:text" json:"content,omitempty" form:"content"`
|
|
Slug string `gorm:"type:varchar(254);not null;uniqueIndex" json:"slug" form:"slug"`
|
|
Categories []Category `gorm:"many2many:post_categories;" json:"categories,omitempty" form:"categories"`
|
|
Tags []Tag `gorm:"many2many:post_tags;" json:"tags,omitempty" form:"tags"`
|
|
}
|
|
|
|
type CategoryView struct {
|
|
gorm.Model
|
|
CategoryID uint `json:"category_id"`
|
|
IPAddress string `gorm:"type:varchar(45)" json:"ip_address,omitempty"`
|
|
}
|
|
|
|
type Comment struct {
|
|
gorm.Model
|
|
UserID uint `json:"user_id"`
|
|
PostID uint `json:"post_id"`
|
|
Body string `gorm:"type:text" json:"body,omitempty"`
|
|
}
|