relation.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package http
  2. import (
  3. "strconv"
  4. model "go-common/app/interface/main/app-interface/model/relation"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // followings get user's following list.
  9. func followings(c *bm.Context) {
  10. var (
  11. mid, vmid int64
  12. pn, ps int
  13. version uint64
  14. self bool
  15. err error
  16. )
  17. params := c.Request.Form
  18. midInter, ok := c.Get("mid")
  19. if ok {
  20. mid = midInter.(int64)
  21. }
  22. versionStr := params.Get("re_version")
  23. order := params.Get("order")
  24. if vmid, err = strconv.ParseInt(params.Get("vmid"), 10, 64); err != nil || vmid < 1 {
  25. c.JSON(nil, ecode.RequestErr)
  26. return
  27. }
  28. self = mid == vmid
  29. if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
  30. pn = 1
  31. }
  32. if !self && pn > 5 {
  33. c.JSON(nil, ecode.RelFollowingGuestLimit)
  34. return
  35. }
  36. if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 50 {
  37. ps = 50
  38. }
  39. if versionStr != "" {
  40. if version, err = strconv.ParseUint(versionStr, 10, 64); err != nil {
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. }
  45. if order != "asc" {
  46. order = "desc"
  47. }
  48. followings, crc32v, total, err := relSvr.Followings(c, vmid, mid, pn, ps, version, order)
  49. c.JSON(struct {
  50. List []*model.Following `json:"list"`
  51. ReVersion uint32 `json:"re_version"`
  52. Total int `json:"total"`
  53. }{followings, crc32v, total}, err)
  54. }
  55. func tag(c *bm.Context) {
  56. var (
  57. mid, tid int64
  58. pn, ps int
  59. err error
  60. )
  61. params := c.Request.Form
  62. midInter, _ := c.Get("mid")
  63. mid = midInter.(int64)
  64. if tid, err = strconv.ParseInt(params.Get("tagid"), 10, 64); err != nil {
  65. c.JSON(nil, ecode.RequestErr)
  66. return
  67. }
  68. if pn, _ = strconv.Atoi(params.Get("pn")); pn < 1 {
  69. pn = 1
  70. }
  71. if ps, _ = strconv.Atoi(params.Get("ps")); ps < 1 || ps > 50 {
  72. ps = 50
  73. }
  74. c.JSON(relSvr.Tag(c, mid, tid, pn, ps))
  75. }