2025-06-19 10:35:26 +08:00

77 lines
2.1 KiB
Go

package schema
import (
"github.com/google/uuid"
"gitlab.guxuan.icu/jinshan_community/pkg/util"
"gorm.io/gorm"
)
// Defining the `Shop` struct.
type Shop struct {
util.BaseModel
Title string `json:"title" gorm:"size:128;not null;index;comment:标题"`
Introduce string `json:"introduce" gorm:"size:1024;comment:介绍"`
Cover string `json:"cover" gorm:"size:2048;not null;comment:封面"`
Images *[]string `json:"images" gorm:"serializer:json;comment:详图数组"`
Content string `json:"content" gorm:"type:text;not null;comment:详情"`
Latitude float64 `json:"latitude" gorm:"type:float;not null;comment:纬度"`
Longitude float64 `json:"longitude" gorm:"type:float;not null;comment:经度"`
Status string `json:"status" gorm:"size:20;index;comment:状态"`
}
func (c *Shop) BeforeCreate(tx *gorm.DB) (err error) {
if c.ID == "" {
c.ID = uuid.New().String()
}
return
}
// Defining the query parameters for the `Shop` struct.
type ShopQueryParam struct {
util.PaginationParam
}
// Defining the query options for the `Shop` struct.
type ShopQueryOptions struct {
util.QueryOptions
}
// Defining the query result for the `Shop` struct.
type ShopQueryResult struct {
Data Shops
PageResult *util.PaginationResult
}
// Defining the slice of `Shop` struct.
type Shops []*Shop
// Defining the data structure for creating a `Shop` struct.
type ShopForm struct {
Title string `json:"title"`
Introduce string `json:"introduce" `
Cover string `json:"cover" `
Images *[]string `json:"images" `
Content string `json:"content" `
Latitude float64 `json:"latitude" `
Longitude float64 `json:"longitude"`
Status string `json:"status" `
}
// A validation function for the `ShopForm` struct.
func (a *ShopForm) Validate() error {
return nil
}
// Convert `ShopForm` to `Shop` object.
func (a *ShopForm) FillTo(shop *Shop) error {
shop.Title = a.Title
shop.Introduce = a.Introduce
shop.Cover = a.Cover
shop.Images = a.Images
shop.Content = a.Content
shop.Latitude = a.Latitude
shop.Longitude = a.Longitude
shop.Status = a.Status
return nil
}