jinshan/internal/mods/common/schema/surrounding_service.go
2025-06-19 10:35:26 +08:00

77 lines
2.4 KiB
Go

package schema
import (
"github.com/google/uuid"
"gitlab.guxuan.icu/jinshan_community/pkg/util"
"gorm.io/gorm"
)
// Defining the `SurroundingService` struct.
type SurroundingService struct {
util.BaseModel
TypeID string `json:"typeId" gorm:"type:char(36);index;not null;comment:分类id"`
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:图片"`
Content string `json:"content" gorm:"type:text;comment:内容"`
Sequence int `json:"sequence" gorm:"index;default:0;comment:排序"`
Link string `json:"link" gorm:"size:2048;comment:链接"`
Status string `json:"status" gorm:"size:20;index;comment:状态"`
}
func (c *SurroundingService) BeforeCreate(tx *gorm.DB) (err error) {
if c.ID == "" {
c.ID = uuid.New().String()
}
return
}
// Defining the query parameters for the `SurroundingService` struct.
type SurroundingServiceQueryParam struct {
util.PaginationParam
}
// Defining the query options for the `SurroundingService` struct.
type SurroundingServiceQueryOptions struct {
util.QueryOptions
}
// Defining the query result for the `SurroundingService` struct.
type SurroundingServiceQueryResult struct {
Data SurroundingServices
PageResult *util.PaginationResult
}
// Defining the slice of `SurroundingService` struct.
type SurroundingServices []*SurroundingService
// Defining the data structure for creating a `SurroundingService` struct.
type SurroundingServiceForm struct {
TypeID string `json:"typeId" `
Title string `json:"title" `
Desc string `json:"desc" `
Img string `json:"img" `
Content string `json:"content" `
Sequence int `json:"sequence"`
Link string `json:"link"`
Status string `json:"status"`
}
// A validation function for the `SurroundingServiceForm` struct.
func (a *SurroundingServiceForm) Validate() error {
return nil
}
// Convert `SurroundingServiceForm` to `SurroundingService` object.
func (a *SurroundingServiceForm) FillTo(surroundingService *SurroundingService) error {
surroundingService.TypeID = a.TypeID
surroundingService.Title = a.Title
surroundingService.Desc = a.Desc
surroundingService.Img = a.Img
surroundingService.Content = a.Content
surroundingService.Sequence = a.Sequence
surroundingService.Link = a.Link
surroundingService.Status = a.Status
return nil
}