75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package schema
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"gitlab.guxuan.icu/jinshan_community/pkg/util"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Defining the `Banner` struct.
|
|
type Banner struct {
|
|
util.BaseModel
|
|
Title string `json:"title" gorm:"size:128;index;comment:标题"`
|
|
Desc string `json:"desc" gorm:"size:128;comment:介绍"`
|
|
Img string `json:"img" gorm:"size:2048;comment:图片"`
|
|
Sequence int `json:"sequence" gorm:"index;default:0;comment:排序"`
|
|
Typer string `json:"type" gorm:"index;comment:类型"`
|
|
Link string `json:"link" gorm:"size:2048;comment:链接"`
|
|
Status string `json:"status" gorm:"size:20;index;comment:状态"`
|
|
}
|
|
|
|
func (c *Banner) BeforeCreate(tx *gorm.DB) (err error) {
|
|
if c.ID == "" {
|
|
c.ID = uuid.New().String()
|
|
}
|
|
return
|
|
}
|
|
|
|
// Defining the query parameters for the `Banner` struct.
|
|
type BannerQueryParam struct {
|
|
util.PaginationParam
|
|
}
|
|
|
|
// Defining the query options for the `Banner` struct.
|
|
type BannerQueryOptions struct {
|
|
util.QueryOptions
|
|
}
|
|
|
|
// Defining the query result for the `Banner` struct.
|
|
type BannerQueryResult struct {
|
|
Data Banners
|
|
PageResult *util.PaginationResult
|
|
}
|
|
|
|
// Defining the slice of `Banner` struct.
|
|
type Banners []*Banner
|
|
|
|
// Defining the data structure for creating a `Banner` struct.
|
|
type BannerForm struct {
|
|
Title string `json:"title"`
|
|
Desc string `json:"desc"`
|
|
Img string `json:"img"`
|
|
Sequence int `json:"sequence"`
|
|
Link string `json:"link"`
|
|
Typer string `json:"type"`
|
|
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// A validation function for the `BannerForm` struct.
|
|
func (a *BannerForm) Validate() error {
|
|
return nil
|
|
}
|
|
|
|
// Convert `BannerForm` to `Banner` object.
|
|
func (a *BannerForm) FillTo(banner *Banner) error {
|
|
banner.Title = a.Title
|
|
banner.Desc = a.Desc
|
|
banner.Img = a.Img
|
|
banner.Sequence = a.Sequence
|
|
banner.Link = a.Link
|
|
banner.Typer = a.Typer
|
|
banner.Status = a.Status
|
|
return nil
|
|
}
|