params.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package model
  2. import (
  3. xtime "go-common/library/time"
  4. "time"
  5. )
  6. // Pagination is
  7. type Pagination struct {
  8. Sort string `form:"sort"`
  9. Order string `form:"order"`
  10. PS int `form:"ps" validate:"min=0,max=50"`
  11. PN int `form:"pn" validate:"min=0"`
  12. MTimeFrom string `form:"mtime_from"`
  13. MTimeTo string `form:"mtime_to"`
  14. }
  15. // FollowersParam is
  16. type FollowersParam struct {
  17. Pagination
  18. Fid int64 `form:"fid" validate:"min=1,required"`
  19. Mid int64 `form:"mid" validate:"min=0"`
  20. }
  21. // FollowingsParam is
  22. type FollowingsParam struct {
  23. Pagination
  24. Mid int64 `form:"mid" validate:"min=1,required"`
  25. Fid int64 `form:"fid" validate:"min=0"`
  26. }
  27. // LogsParam is
  28. type LogsParam struct {
  29. Mid int64 `form:"mid" validate:"min=1,required"`
  30. Fid int64 `form:"fid" validate:"min=1,required"`
  31. }
  32. // ParseTime is
  33. func ParseTime(ts string) (xt xtime.Time, err error) {
  34. var (
  35. t time.Time
  36. )
  37. if t, err = time.Parse("2006-01-02 15:04:05", ts); err != nil {
  38. return
  39. }
  40. xt.Scan(t)
  41. return
  42. }
  43. // Desc is
  44. func (p Pagination) Desc() bool {
  45. return p.Sort == "desc"
  46. }
  47. // ArgMid is
  48. type ArgMid struct {
  49. Mid int64 `form:"mid" validate:"min=1,required"`
  50. }
  51. // ArgMids is
  52. type ArgMids struct {
  53. Mids []int64 `form:"mids,split" validate:"dive,gt=0"`
  54. }