52 lines
1.9 KiB
Go
52 lines
1.9 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"`
|
|
Images string `gorm:"type:text;not null" json:"images"`
|
|
Content string `gorm:"type:text" json:"content,omitempty"`
|
|
Slug string `gorm:"type:varchar(254);not null;uniqueIndex" json:"slug"`
|
|
Categories []Category `gorm:"many2many:post_categories;" json:"categories,omitempty"`
|
|
Tags []Tag `gorm:"many2many:post_tags;" json:"tags,omitempty"`
|
|
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"`
|
|
}
|
|
|
|
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"`
|
|
}
|