85 lines
2.7 KiB
Go
85 lines
2.7 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/guxuan/hailin_service/internal/config"
|
|
"github.com/guxuan/hailin_service/pkg/util"
|
|
)
|
|
|
|
const (
|
|
TeamStatusDisabled = "disabled"
|
|
TeamStatusEnabled = "enabled"
|
|
)
|
|
|
|
var (
|
|
TeamOrderParams = []util.OrderByParam{
|
|
{Field: "created_at", Direction: util.DESC},
|
|
{Field: "sequence", Direction: util.DESC},
|
|
}
|
|
TeamOrderNoCreatedAtParams = []util.OrderByParam{
|
|
{Field: "sequence", Direction: util.DESC},
|
|
}
|
|
)
|
|
|
|
// Article management for RBAC
|
|
type Team 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)
|
|
Area string `json:"area" gorm:"size:1024"`
|
|
Rank *[]string `json:"rank" gorm:"serializer:json"` // 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 *Team) TableName() string {
|
|
return config.C.FormatTableName("team")
|
|
}
|
|
|
|
// Defining the query parameters for the `Menu` struct.
|
|
type TeamQueryParam struct {
|
|
util.PaginationParam
|
|
LikeName string `form:"name"` // Display name of menu
|
|
Status string `form:"status"` // Status of menu (enabled, disabled)
|
|
}
|
|
|
|
// Defining the query options for the `Menu` struct.
|
|
type TeamQueryOptions struct {
|
|
util.QueryOptions
|
|
}
|
|
|
|
// Defining the query result for the `Menu` struct.
|
|
type TeamQueryResult struct {
|
|
Data Teams
|
|
PageResult *util.PaginationResult
|
|
}
|
|
|
|
// Defining the slice of `Menu` struct.
|
|
type Teams []*Team
|
|
|
|
func (a Teams) Len() int {
|
|
return len(a)
|
|
}
|
|
|
|
type TeamForm struct {
|
|
Name string `json:"name" binding:"required,max=128"` // Display name of menu
|
|
Sequence int `json:"sequence"` // Sequence for sorting (Order by desc)
|
|
Area string `json:"area" `
|
|
Rank *[]string `json:"rank"` // Type of banner (ban
|
|
Img string `json:"img" ` // Details about banner
|
|
Status string `json:"status" binding:"required,oneof=disabled enabled"` // Status of menu (enabled, disabled)
|
|
}
|
|
|
|
func (a *TeamForm) FillTo(team *Team) error {
|
|
team.Name = a.Name
|
|
team.Area = a.Area
|
|
team.Sequence = a.Sequence
|
|
team.Img = a.Img
|
|
team.Rank = a.Rank
|
|
team.Status = a.Status
|
|
return nil
|
|
}
|