You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
61 lines
1.3 KiB
4 months ago
|
package base
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"gorm.io/gorm"
|
||
|
"product/backend/models"
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type GetReq struct {
|
||
|
ID uint `form:"id"`
|
||
|
Keyword string `form:"keyword"`
|
||
|
models.Pager
|
||
|
}
|
||
|
|
||
|
const PageSizeMax = 100
|
||
|
const PageSizeDefault = 12
|
||
|
const PageSizeAll = -1
|
||
|
const PageIndexDefault = 1
|
||
|
const SortFieldDefault = "order"
|
||
|
const SortOrderDefault = "DESC"
|
||
|
|
||
|
func (getReq *GetReq) Init() {
|
||
|
if getReq.PageIndex <= 0 {
|
||
|
getReq.PageIndex = PageIndexDefault
|
||
|
}
|
||
|
|
||
|
if getReq.PageSize < PageSizeAll || getReq.PageSize > PageSizeMax || getReq.PageSize == 0 {
|
||
|
getReq.PageSize = PageSizeDefault
|
||
|
}
|
||
|
|
||
|
if getReq.SortField == "" {
|
||
|
getReq.SortField = SortFieldDefault
|
||
|
}
|
||
|
|
||
|
getReq.SortOrder = strings.ToUpper(getReq.SortOrder)
|
||
|
if getReq.SortOrder != "ASC" && getReq.SortOrder != "DESC" {
|
||
|
getReq.SortOrder = SortOrderDefault
|
||
|
}
|
||
|
}
|
||
|
|
||
|
type DelReq struct {
|
||
|
ID uint `form:"id"`
|
||
|
//IDs []uint `form:"ids[]"`
|
||
|
}
|
||
|
|
||
|
func (delReq *DelReq) BindAndInit(ctx *gin.Context) error {
|
||
|
if err := ctx.ShouldBindQuery(&delReq); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type Model struct {
|
||
|
ID uint `gorm:"primarykey" json:"id"`
|
||
|
CreatedAt time.Time `json:"createdAt"`
|
||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||
|
}
|