85 lines
2.8 KiB
Go
85 lines
2.8 KiB
Go
package schema
|
|
|
|
import (
|
|
"github.com/guxuan/hailin_service/internal/config"
|
|
"github.com/guxuan/hailin_service/pkg/util"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
BannerStatusDisabled = "disabled"
|
|
BannerStatusEnabled = "enabled"
|
|
)
|
|
|
|
var (
|
|
BannerOrderParams = []util.OrderByParam{
|
|
{Field: "created_at", Direction: util.DESC},
|
|
{Field: "sequence", Direction: util.DESC},
|
|
}
|
|
BannerOrderNoCreatedAtParams = []util.OrderByParam{
|
|
{Field: "sequence", Direction: util.DESC},
|
|
}
|
|
)
|
|
|
|
// Menu management for RBAC
|
|
type Banner struct {
|
|
ID string `json:"id" gorm:"size:20;primarykey;"` // Unique ID
|
|
Name string `json:"name" gorm:"size:128;not null;index"` // Display name of banner
|
|
Img string `json:"img" gorm:"size:1024"` // Details about banner
|
|
Sequence int `json:"sequence" gorm:"index;"` // Sequence for sorting (Order by desc)
|
|
Link string `json:"link" gorm:"size:1024;"`
|
|
Typer int `json:"type" gorm:"size:11;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 *Banner) TableName() string {
|
|
return config.C.FormatTableName("banner")
|
|
}
|
|
|
|
// Defining the query parameters for the `Menu` struct.
|
|
type BannerQueryParam struct {
|
|
util.PaginationParam
|
|
LikeName string `form:"name"` // Display name of menu
|
|
Typer int `form:"type" bind:"required,max=11"`
|
|
Status string `form:"status"` // Status of menu (enabled, disabled)
|
|
}
|
|
|
|
// Defining the query options for the `Menu` struct.
|
|
type BannerQueryOptions struct {
|
|
util.QueryOptions
|
|
}
|
|
|
|
// Defining the query result for the `Menu` struct.
|
|
type BannerQueryResult struct {
|
|
Data Banners
|
|
PageResult *util.PaginationResult
|
|
}
|
|
|
|
// Defining the slice of `Menu` struct.
|
|
type Banners []*Banner
|
|
|
|
func (a Banners) Len() int {
|
|
return len(a)
|
|
}
|
|
|
|
type BannerForm struct {
|
|
Name string `json:"name" binding:"required,max=128"` // Display name of menu
|
|
Sequence int `json:"sequence"` // Sequence for sorting (Order by desc)
|
|
Link string `json:"link" `
|
|
Typer int `json:"type" binding:"required"` // Type of menu (banner, link) // Parent menu``
|
|
Img string `json:"img" gorm:"size:1024"` // Details about banner
|
|
Status string `json:"status" binding:"required,oneof=disabled enabled"` // Status of menu (enabled, disabled)
|
|
}
|
|
|
|
func (a *BannerForm) FillTo(banner *Banner) error {
|
|
banner.Name = a.Name
|
|
banner.Sequence = a.Sequence
|
|
banner.Img = a.Img
|
|
banner.Link = a.Link
|
|
banner.Typer = a.Typer
|
|
banner.Status = a.Status
|
|
return nil
|
|
}
|