68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package schema
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"gitlab.guxuan.icu/jinshan_community/pkg/util"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Defining the `Notice` struct.
|
|
type Notice struct {
|
|
util.BaseModel
|
|
Title string `json:"title" gorm:"size:128;index;comment:标题"`
|
|
Desc string `json:"desc" gorm:"size:128;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 *Notice) BeforeCreate(tx *gorm.DB) (err error) {
|
|
if c.ID == "" {
|
|
c.ID = uuid.New().String()
|
|
}
|
|
return
|
|
}
|
|
|
|
// Defining the query parameters for the `Notice` struct.
|
|
type NoticeQueryParam struct {
|
|
util.PaginationParam
|
|
}
|
|
|
|
// Defining the query options for the `Notice` struct.
|
|
type NoticeQueryOptions struct {
|
|
util.QueryOptions
|
|
}
|
|
|
|
// Defining the query result for the `Notice` struct.
|
|
type NoticeQueryResult struct {
|
|
Data Notices
|
|
PageResult *util.PaginationResult
|
|
}
|
|
|
|
// Defining the slice of `Notice` struct.
|
|
type Notices []*Notice
|
|
|
|
// Defining the data structure for creating a `Notice` struct.
|
|
type NoticeForm struct {
|
|
Title string `json:"title"`
|
|
Desc string `json:"desc"`
|
|
Sequence int `json:"sequence"`
|
|
Link string `json:"link"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// A validation function for the `NoticeForm` struct.
|
|
func (a *NoticeForm) Validate() error {
|
|
return nil
|
|
}
|
|
|
|
// Convert `NoticeForm` to `Notice` object.
|
|
func (a *NoticeForm) FillTo(notice *Notice) error {
|
|
notice.Title = a.Title
|
|
notice.Desc = a.Desc
|
|
notice.Sequence = a.Sequence
|
|
notice.Link = a.Link
|
|
notice.Status = a.Status
|
|
return nil
|
|
}
|