package schema import ( "time" "github.com/guxuan/hailin_service/internal/config" "github.com/guxuan/hailin_service/pkg/util" ) const ( ArticleStatusDisabled = "disabled" ArticleStatusEnabled = "enabled" ) var ( ArticleOrderParams = []util.OrderByParam{ {Field: "created_at", Direction: util.DESC}, {Field: "sequence", Direction: util.DESC}, } ArticleOrderNoCreatedAtParams = []util.OrderByParam{ {Field: "sequence", Direction: util.DESC}, } ) // Article management for RBAC type Article struct { ID string `json:"id" gorm:"size:20;primarykey;"` // Unique ID Title string `json:"title" gorm:"size:128;not null;index"` // Display name of banner Img string `json:"img" gorm:"size:1024"` // Details about banner Sequence int `json:"sequence" gorm:"index;"` // Sequence for sorting (Order by desc) Link string `json:"link" gorm:"size:1024;"` Content string `json:"content" gorm:"type:text;comment:详情"` PushAt string `json:"pushAt" gorm:"size:50;index"` Typer string `json:"type" gorm:"size:50;not null;index"` // Type of banner (banner, link) // Parent menu`` Status string `json:"status" gorm:"size:20;index"` // Status of banner (enabled, disabled) // Child menus CreatedAt time.Time `json:"created_at" gorm:"index;"` // Create time UpdatedAt time.Time `json:"updated_at" gorm:"index;"` // Update time } func (a *Article) TableName() string { return config.C.FormatTableName("article") } // Defining the query parameters for the `Menu` struct. type ArticleQueryParam struct { util.PaginationParam LikeTitle string `form:"title"` // Display name of menu Typer string `form:"type" bind:"required,max=50"` Status string `form:"status"` // Status of menu (enabled, disabled) } // Defining the query options for the `Menu` struct. type ArticleQueryOptions struct { util.QueryOptions } // Defining the query result for the `Menu` struct. type ArticleQueryResult struct { Data Articles PageResult *util.PaginationResult } // Defining the slice of `Menu` struct. type Articles []*Article func (a Articles) Len() int { return len(a) } type ArticleForm struct { Title string `json:"title" binding:"required,max=128"` // Display name of menu Sequence int `json:"sequence"` // Sequence for sorting (Order by desc) Link string `json:"link" ` Content string `json:"content"` PushAt string `json:"pushAt"` Typer string `json:"type" binding:"required,oneof=banner home achievement honor talent_center team news"` // Type of menu (banner, link) // Parent menu`` Img string `json:"img" ` // Details about banner Status string `json:"status" binding:"required,oneof=disabled enabled"` // Status of menu (enabled, disabled) } func (a *ArticleForm) FillTo(article *Article) error { article.Title = a.Title article.PushAt = a.PushAt article.Sequence = a.Sequence article.Content = a.Content article.Img = a.Img article.Link = a.Link article.Typer = a.Typer article.Status = a.Status return nil }