115 lines
4.1 KiB
Go
115 lines
4.1 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/guxuan/hailin_service/internal/config"
|
|
"github.com/guxuan/hailin_service/pkg/util"
|
|
)
|
|
|
|
const (
|
|
ProductStatusDisabled = "disabled"
|
|
ProudctStatusEnabled = "enabled"
|
|
)
|
|
|
|
var (
|
|
ProductOrderParams = []util.OrderByParam{
|
|
{Field: "created_at", Direction: util.DESC},
|
|
{Field: "sequence", Direction: util.DESC},
|
|
}
|
|
ProductOrderNoCreatedAtParams = []util.OrderByParam{
|
|
{Field: "sequence", Direction: util.DESC},
|
|
}
|
|
)
|
|
|
|
// Article management for RBAC
|
|
type Product struct {
|
|
ID string `json:"id" gorm:"size:20;primarykey;"`
|
|
CategoryID uint `json:"categoryID" gorm:"index;"`
|
|
Title string `json:"title" gorm:"size:128;not null;index"` // Display name of banner
|
|
Images []string `json:"images" gorm:"serializer:json"`
|
|
Code string `json:"code" gorm:"size:50"` // Details about banner
|
|
Sequence int `json:"sequence" gorm:"index;"` // Sequence for sorting (Order by desc)
|
|
Compose string `json:"compose" gorm:"size:1024;"`
|
|
Target string `json:"target" gorm:"size:1024"`
|
|
Standard *[]ProductStandard `json:"standard" gorm:"serializer:json"`
|
|
Feature string `json:"feature" gorm:"size:2048"` // 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
|
|
}
|
|
type ProductStandard struct {
|
|
Label string
|
|
Value string
|
|
}
|
|
|
|
type ProductCategory struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
Label string `json:"label" gorm:"size:128;not null;index"` // Display name of banner
|
|
ParentID uint `json:"parentID" gorm:"size:50;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 *Product) TableName() string {
|
|
return config.C.FormatTableName("product")
|
|
}
|
|
func (a *ProductCategory) TableName() string {
|
|
return config.C.FormatTableName("product_category")
|
|
}
|
|
|
|
// Defining the query parameters for the `Menu` struct.
|
|
type ProductQueryParam struct {
|
|
util.PaginationParam
|
|
LikeTitle string `form:"title"` // Display name of menu
|
|
CategoryID uint `form:"categoryId"`
|
|
Code string `form:"code" `
|
|
Status string `form:"status"` // Status of menu (enabled, disabled)
|
|
}
|
|
|
|
// Defining the query options for the `Menu` struct.
|
|
type ProductQueryOptions struct {
|
|
util.QueryOptions
|
|
}
|
|
|
|
// Defining the query result for the `Menu` struct.
|
|
type ProductQueryResult struct {
|
|
Data Products
|
|
PageResult *util.PaginationResult
|
|
}
|
|
|
|
// Defining the slice of `Menu` struct.
|
|
type Products []*Product
|
|
|
|
func (a Products) Len() int {
|
|
return len(a)
|
|
}
|
|
|
|
type ProductForm struct {
|
|
CategoryID uint `json:"categoryID" binding:"required,max=11"`
|
|
Title string `json:"title" binding:"required,max=128"` // Display name of menu
|
|
Images []string `json:"images"`
|
|
Sequence int `json:"sequence"` // Sequence for sorting (Order by desc)
|
|
Code string `json:"code" `
|
|
Compose string `json:"compose"`
|
|
Feature string `json:"feature"`
|
|
Target string `json:"target" ` // Type of menu (banner, link) // Parent menu``
|
|
Standard *[]ProductStandard `json:"standard" ` // Details about banner
|
|
Status string `json:"status" binding:"required,oneof=disabled enabled"`
|
|
}
|
|
|
|
func (a *ProductForm) FillTo(product *Product) error {
|
|
product.Title = a.Title
|
|
product.Compose = a.Compose
|
|
product.Sequence = a.Sequence
|
|
product.Code = a.Code
|
|
product.CategoryID = a.CategoryID
|
|
product.Standard = a.Standard
|
|
product.Images = a.Images
|
|
product.Feature = a.Feature
|
|
product.Target = a.Target
|
|
product.Status = a.Status
|
|
return nil
|
|
}
|