2025-06-19 10:30:46 +08:00

94 lines
2.9 KiB
Go

package schema
import (
"time"
"github.com/guxuan/hailin_service/internal/config"
"github.com/guxuan/hailin_service/pkg/util"
)
const (
VideoStatusDisabled = "disabled"
VideoStatusEnabled = "enabled"
)
var (
VideoOrderParams = []util.OrderByParam{
{Field: "created_at", Direction: util.DESC},
{Field: "sequence", Direction: util.DESC},
}
VideoOrderNoCreatedAtParams = []util.OrderByParam{
{Field: "sequence", Direction: util.DESC},
}
)
// Article management for RBAC
type Video 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
Subheading string `json:"subheading" gorm:"size:128;index"` // Display name of banner
SmallImg string `json:"smallImg" gorm:"size:1024"`
VideoUrl string `json:"videoUrl" gorm:"size:1024"`
FullImg string `json:"fullImg" 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;"`
PushAt string `json:"pushAt" gorm:"size:50;index"`
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 *Video) TableName() string {
return config.C.FormatTableName("video")
}
// Defining the query parameters for the `Menu` struct.
type VideoQueryParam struct {
util.PaginationParam
LikeTitle string `form:"title"` // Display name of menu
Typer string `form:"type" bind:"required,max=50"`
Status string `form:"status"` // Status of menu (enabled, disabled)
}
// Defining the query options for the `Menu` struct.
type VideoQueryOptions struct {
util.QueryOptions
}
// Defining the query result for the `Menu` struct.
type VideoQueryResult struct {
Data Videos
PageResult *util.PaginationResult
}
// Defining the slice of `Menu` struct.
type Videos []*Video
func (a Videos) Len() int {
return len(a)
}
type VideoForm struct {
Title string `json:"title" binding:"required,max=128"` // Display name of menu
Sequence int `json:"sequence"` // Sequence for sorting (Order by desc)
Link string `json:"link" `
PushAt string `json:"pushAt"`
VideoUrl string `json:"videoUrl"`
SmallImg string `json:"smallImg" `
FullImg string `json:"fullImg" `
Status string `json:"status" binding:"required,oneof=disabled enabled"` // Status of menu (enabled, disabled)
}
func (a *VideoForm) FillTo(video *Video) error {
video.Title = a.Title
video.PushAt = a.PushAt
video.VideoUrl = a.VideoUrl
video.Sequence = a.Sequence
video.SmallImg = a.SmallImg
video.FullImg = a.FullImg
video.Link = a.Link
video.Status = a.Status
return nil
}