Files
new-api/model/document_category.go
T
admin e83ec743c8
Docker Build / Build and Push Docker Image (push) Failing after 1m35s
feat: add DaisyUI frontend theme and document management system
2026-06-13 01:36:06 +08:00

39 lines
1.1 KiB
Go

package model
import (
"time"
)
type DocumentCategory struct {
Id int `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"not null"`
Slug string `json:"slug" gorm:"uniqueIndex;not null"`
ParentId *int `json:"parent_id" gorm:"index"`
SortOrder int `json:"sort_order" gorm:"default:0"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
}
func GetDocumentCategories() ([]*DocumentCategory, error) {
var categories []*DocumentCategory
err := DB.Order("sort_order ASC, id ASC").Find(&categories).Error
return categories, err
}
func GetDocumentCategoryTree() ([]*DocumentCategory, error) {
var categories []*DocumentCategory
err := DB.Order("sort_order ASC, id ASC").Find(&categories).Error
return categories, err
}
func CreateDocumentCategory(category *DocumentCategory) error {
return DB.Create(category).Error
}
func UpdateDocumentCategory(category *DocumentCategory) error {
return DB.Model(category).Select("name", "slug", "parent_id", "sort_order").Updates(category).Error
}
func DeleteDocumentCategory(id int) error {
return DB.Delete(&DocumentCategory{}, id).Error
}