upper.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package http
  2. import (
  3. "strconv"
  4. "context"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/xstr"
  9. )
  10. func upperPassed(c *bm.Context) {
  11. params := c.Request.Form
  12. midStr := params.Get("mid")
  13. pnStr := params.Get("pn")
  14. psStr := params.Get("ps")
  15. // check params
  16. mid, err := strconv.ParseInt(midStr, 10, 64)
  17. if err != nil {
  18. log.Error("strconv.ParseInt(%s) error(%v)", midStr, err)
  19. c.JSON(nil, ecode.RequestErr)
  20. return
  21. }
  22. // deal
  23. pn, err := strconv.Atoi(pnStr)
  24. if err != nil || pn < 1 {
  25. pn = 1
  26. }
  27. ps, err := strconv.Atoi(psStr)
  28. if err != nil || ps < 1 || ps > 100 {
  29. ps = 20
  30. }
  31. as, err := arcSvc.UpperPassed3(c, mid, pn, ps)
  32. if err != nil {
  33. if ec := ecode.Cause(err); ec != ecode.NothingFound {
  34. log.Error("arcSvc.UpperPassed(%d) error(%d)", mid, err)
  35. }
  36. c.JSON(nil, err)
  37. return
  38. }
  39. c.JSON(as, err)
  40. }
  41. // upperCount write the count of archives of Up.
  42. func upperCount(c *bm.Context) {
  43. params := c.Request.Form
  44. midStr := params.Get("mid")
  45. // check params
  46. mid, err := strconv.ParseInt(midStr, 10, 64)
  47. if err != nil {
  48. log.Error("strconv.ParseInt(%s) error(%v)", midStr, err)
  49. c.JSON(nil, ecode.RequestErr)
  50. return
  51. }
  52. count, err := arcSvc.UpperCount(c, mid)
  53. if err != nil {
  54. c.JSON(nil, err)
  55. log.Error("arcSvc.UpperCount(%d) error(%d)", mid, err)
  56. return
  57. }
  58. var res struct {
  59. Count int `json:"count"`
  60. }
  61. res.Count = count
  62. c.JSON(res, nil)
  63. }
  64. // uppersCount uppers count
  65. func uppersCount(c *bm.Context) {
  66. params := c.Request.Form
  67. midsStr := params.Get("mids")
  68. // check params
  69. mids, err := xstr.SplitInts(midsStr)
  70. if err != nil {
  71. log.Error("query mids(%s) split error(%v)", midsStr, err)
  72. c.JSON(nil, ecode.RequestErr)
  73. return
  74. }
  75. if len(mids) > 20 {
  76. log.Error("query mids(%s) too long", midsStr)
  77. c.JSON(nil, ecode.RequestErr)
  78. return
  79. }
  80. c.JSON(arcSvc.UppersCount(c, mids))
  81. }
  82. // upperCache delete user cache.
  83. func upperCache(c *bm.Context) {
  84. params := c.Request.Form
  85. midStr := params.Get("mid")
  86. action := params.Get("modifiedAttr")
  87. // check params
  88. mid, err := strconv.ParseInt(midStr, 10, 64)
  89. if err != nil {
  90. c.JSON(nil, ecode.RequestErr)
  91. return
  92. }
  93. if action == "updateUname" || action == "updateFace" || action == "updateByAdmin" {
  94. c.JSON(nil, arcSvc.UpperCache(context.TODO(), mid, action))
  95. }
  96. }