93 lines
3.2 KiB
Go
93 lines
3.2 KiB
Go
package schema
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"gitlab.guxuan.icu/jinshan_community/pkg/util"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
)
|
|
|
|
// Defining the `Activity` struct.
|
|
type Activity struct {
|
|
util.BaseModel
|
|
CategoryID string `json:"categoryId" gorm:"type:char(36);index;comment:分类id"`
|
|
Title string `json:"title" gorm:"size:128;not null;index;comment:标题"`
|
|
Cover string `json:"cover" gorm:"size:2048;not null;comment:封面"`
|
|
Images *[]string `json:"images" gorm:"serializer:json;comment:详图数组"`
|
|
StartAt *time.Time `json:"startAt" gorm:"not null;comment:开始时间"`
|
|
EndAt *time.Time `json:"endAt" gorm:"not null;comment:结束时间"`
|
|
StartSignupAt *time.Time `json:"startSignupAt" gorm:"not null;comment:报名开始时间"`
|
|
EndSignupAt *time.Time `json:"endSignupAt" gorm:"not null;comment:报名结束时间"`
|
|
MaxSignupNum int `json:"maxSignupNum" gorm:"not null;comment:最大报名人数"`
|
|
SignupNum int `json:"signupNum" gorm:"not null;default:0;comment:当前报名人数"`
|
|
Address string `json:"address" gorm:"size:1024;not null;comment:活动地址"`
|
|
Content string `json:"content" gorm:"type:text;not null;comment:活动详情"`
|
|
Status string `json:"status" gorm:"size:20;index;comment:状态"`
|
|
}
|
|
|
|
func (c *Activity) BeforeCreate(tx *gorm.DB) (err error) {
|
|
if c.ID == "" {
|
|
c.ID = uuid.New().String()
|
|
}
|
|
return
|
|
}
|
|
|
|
// Defining the query parameters for the `Activity` struct.
|
|
type ActivityQueryParam struct {
|
|
util.PaginationParam
|
|
}
|
|
|
|
// Defining the query options for the `Activity` struct.
|
|
type ActivityQueryOptions struct {
|
|
util.QueryOptions
|
|
}
|
|
|
|
// Defining the query result for the `Activity` struct.
|
|
type ActivityQueryResult struct {
|
|
Data Activities
|
|
PageResult *util.PaginationResult
|
|
}
|
|
|
|
// Defining the slice of `Activity` struct.
|
|
type Activities []*Activity
|
|
|
|
// Defining the data structure for creating a `Activity` struct.
|
|
type ActivityForm struct {
|
|
CategoryID string `json:"categoryId"`
|
|
Title string `json:"title" `
|
|
Cover string `json:"cover" `
|
|
Images *[]string `json:"images"`
|
|
StartAt *time.Time `json:"startAt"`
|
|
EndAt *time.Time `json:"endAt"`
|
|
StartSignupAt *time.Time `json:"startSignupAt"`
|
|
EndSignupAt *time.Time `json:"endSignupAt" `
|
|
MaxSignupNum int `json:"maxSignupNum"`
|
|
SignupNum int `json:"signupNum"`
|
|
Address string `json:"address"`
|
|
Content string `json:"content"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// A validation function for the `ActivityForm` struct.
|
|
func (a *ActivityForm) Validate() error {
|
|
return nil
|
|
}
|
|
|
|
// Convert `ActivityForm` to `Activity` object.
|
|
func (a *ActivityForm) FillTo(activity *Activity) error {
|
|
activity.CategoryID = a.CategoryID
|
|
activity.Title = a.Title
|
|
activity.Cover = a.Cover
|
|
activity.Images = a.Images
|
|
activity.StartAt = a.StartAt
|
|
activity.EndAt = a.EndAt
|
|
activity.StartSignupAt = a.StartSignupAt
|
|
activity.EndSignupAt = a.EndSignupAt
|
|
activity.MaxSignupNum = a.MaxSignupNum
|
|
activity.SignupNum = a.SignupNum
|
|
activity.Address = a.Address
|
|
activity.Content = a.Content
|
|
activity.Status = a.Status
|
|
return nil
|
|
}
|