common.go 1017 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package request
  2. import (
  3. "gorm.io/gorm"
  4. )
  5. // PageInfo Paging common input parameter structure
  6. type PageInfo struct {
  7. Page int `json:"page" form:"page"` // 页码
  8. PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
  9. Keyword string `json:"keyword" form:"keyword"` // 关键字
  10. }
  11. func (r *PageInfo) Paginate() func(db *gorm.DB) *gorm.DB {
  12. return func(db *gorm.DB) *gorm.DB {
  13. if r.Page <= 0 {
  14. r.Page = 1
  15. }
  16. switch {
  17. case r.PageSize > 100:
  18. r.PageSize = 100
  19. case r.PageSize <= 0:
  20. r.PageSize = 10
  21. }
  22. offset := (r.Page - 1) * r.PageSize
  23. return db.Offset(offset).Limit(r.PageSize)
  24. }
  25. }
  26. // GetById Find by id structure
  27. type GetById struct {
  28. ID int `json:"id" form:"id"` // 主键ID
  29. }
  30. func (r *GetById) Uint() uint {
  31. return uint(r.ID)
  32. }
  33. type IdsReq struct {
  34. Ids []int `json:"ids" form:"ids"`
  35. }
  36. // GetAuthorityId Get role by id structure
  37. type GetAuthorityId struct {
  38. AuthorityId uint `json:"authorityId" form:"authorityId"` // 角色ID
  39. }
  40. type Empty struct{}