region.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/service/main/archive/api"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // regionArcs.
  9. func regionArcs(c *bm.Context) {
  10. params := c.Request.Form
  11. ridStr := params.Get("rid")
  12. tpStr := params.Get("type")
  13. pnStr := params.Get("pn")
  14. psStr := params.Get("ps")
  15. // check params
  16. rid, err := strconv.ParseInt(ridStr, 10, 64)
  17. if err != nil {
  18. c.JSON(nil, ecode.RequestErr)
  19. return
  20. }
  21. var tp int64
  22. if tpStr != "" {
  23. if tp, err = strconv.ParseInt(tpStr, 10, 64); err != nil {
  24. c.JSON(nil, ecode.RequestErr)
  25. return
  26. }
  27. }
  28. pn, err := strconv.Atoi(pnStr)
  29. if err != nil || pn < 1 {
  30. pn = 1
  31. }
  32. ps, err := strconv.Atoi(psStr)
  33. if err != nil || ps < 1 || ps > 100 {
  34. ps = 20
  35. }
  36. // service
  37. var (
  38. as []*api.Arc
  39. count int
  40. )
  41. if tp == 0 {
  42. as, count, err = arcSvc.RegionArcs3(c, int16(rid), pn, ps)
  43. } else {
  44. as, count, err = arcSvc.RegionOriginArcs3(c, int16(rid), pn, ps)
  45. }
  46. if err != nil {
  47. c.JSON(nil, err)
  48. return
  49. }
  50. var res struct {
  51. Archives []*api.Arc `json:"archives"`
  52. Page struct {
  53. Count int `json:"count"`
  54. Num int `json:"num"`
  55. Size int `json:"size"`
  56. } `json:"page"`
  57. }
  58. res.Archives = as
  59. res.Page.Num = pn
  60. res.Page.Size = ps
  61. res.Page.Count = count
  62. c.JSON(res, nil)
  63. }
  64. // addRegionArc.
  65. func addRegionArc(c *bm.Context) {
  66. params := c.Request.Form
  67. ridStr := params.Get("rid")
  68. // check params
  69. rid, _ := strconv.ParseInt(ridStr, 10, 64)
  70. c.JSON(nil, arcSvc.AddRegionArcs(c, int16(rid)))
  71. }