80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/guxuan/hailin_service/internal/config"
|
|
"github.com/guxuan/hailin_service/pkg/util"
|
|
)
|
|
|
|
const (
|
|
MemorabiliaStatusDisabled = "disabled"
|
|
MemorabiliaStatusEnabled = "enabled"
|
|
)
|
|
|
|
var (
|
|
MemorabiliaOrderParams = []util.OrderByParam{
|
|
{Field: "sequence", Direction: util.DESC},
|
|
}
|
|
)
|
|
|
|
// Article management for RBAC
|
|
type Memorabilia struct {
|
|
ID string `json:"id" gorm:"size:20;primarykey;"` // Unique ID
|
|
Title string `json:"title" gorm:"size:128;not null;index"` // Display name of banner
|
|
Sequence int `json:"sequence" gorm:"index;default:0"`
|
|
Year int `json:"year" gorm:"size:10;not null;index"` // Type of banner (banner, link) // Parent menu``
|
|
Month int `json:"month" gorm:"size:10;not null;index"` // Type of banner (banner, link) // Parent menu``
|
|
Status string `json:"status" gorm:"size:20;index"` // Status of banner (enabled, disabled) // Child menus
|
|
CreatedAt time.Time `json:"created_at" gorm:"index;"` // Create time
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"index;"` // Update time
|
|
}
|
|
|
|
func (a *Memorabilia) TableName() string {
|
|
return config.C.FormatTableName("memorabilia")
|
|
}
|
|
|
|
// Defining the query parameters for the `Menu` struct.
|
|
type MemorabiliaQueryParam struct {
|
|
util.PaginationParam
|
|
LikeTitle string `form:"title"` // Display name of menu
|
|
Month int `form:"month"`
|
|
Year int `form:"year"`
|
|
Status string `form:"status"` // Status of menu (enabled, disabled)
|
|
}
|
|
|
|
// Defining the query options for the `Menu` struct.
|
|
type MemorabiliaQueryOptions struct {
|
|
util.QueryOptions
|
|
}
|
|
|
|
// Defining the query result for the `Menu` struct.
|
|
type MemorabiliaQueryResult struct {
|
|
Data Memorabilias
|
|
PageResult *util.PaginationResult
|
|
}
|
|
|
|
// Defining the slice of `Menu` struct.
|
|
type Memorabilias []*Memorabilia
|
|
|
|
func (a Memorabilias) Len() int {
|
|
return len(a)
|
|
}
|
|
|
|
type MemorabiliaForm struct {
|
|
Title string `json:"title" binding:"required,max=128"` // Display name of menu
|
|
Sequence int `json:"sequence"` // Sequence for sorting (Order by desc)
|
|
Year int `json:"year"`
|
|
Month int `json:"month"`
|
|
Status string `json:"status" binding:"required,oneof=disabled enabled"` // Status of menu (enabled, disabled)
|
|
}
|
|
|
|
func (a *MemorabiliaForm) FillTo(memorabilia *Memorabilia) error {
|
|
memorabilia.Title = a.Title
|
|
memorabilia.Month = a.Month
|
|
memorabilia.Sequence = a.Sequence
|
|
memorabilia.Year = a.Year
|
|
memorabilia.Status = a.Status
|
|
return nil
|
|
}
|