following.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/service/main/relation/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/time"
  8. )
  9. // followings get user's following list.
  10. func followings(c *bm.Context) {
  11. var (
  12. err error
  13. mid int64
  14. params = c.Request.Form
  15. midStr = params.Get("mid")
  16. )
  17. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  18. c.JSON(nil, ecode.RequestErr)
  19. return
  20. }
  21. c.JSON(relationSvc.Followings(c, mid))
  22. }
  23. // addFollowing add following.
  24. func addFollowing(c *bm.Context) {
  25. var (
  26. err error
  27. mid, fid int64
  28. src uint64
  29. params = c.Request.Form
  30. midStr = params.Get("mid")
  31. fidStr = params.Get("fid")
  32. srcStr = params.Get("src")
  33. )
  34. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  35. c.JSON(nil, ecode.RequestErr)
  36. return
  37. }
  38. if fid, err = strconv.ParseInt(fidStr, 10, 64); err != nil {
  39. c.JSON(nil, ecode.RequestErr)
  40. return
  41. }
  42. if mid <= 0 || fid <= 0 {
  43. c.JSON(nil, ecode.RequestErr)
  44. return
  45. }
  46. if src, err = strconv.ParseUint(srcStr, 10, 8); err != nil {
  47. c.JSON(nil, ecode.RequestErr)
  48. return
  49. }
  50. ric := infocArg(c)
  51. c.JSON(nil, relationSvc.AddFollowing(c, mid, fid, uint8(src), ric))
  52. }
  53. // delFollowing del following.
  54. func delFollowing(c *bm.Context) {
  55. var (
  56. err error
  57. mid, fid int64
  58. src uint64
  59. params = c.Request.Form
  60. midStr = params.Get("mid")
  61. fidStr = params.Get("fid")
  62. srcStr = params.Get("src")
  63. )
  64. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  65. c.JSON(nil, ecode.RequestErr)
  66. return
  67. }
  68. if fid, err = strconv.ParseInt(fidStr, 10, 64); err != nil {
  69. c.JSON(nil, ecode.RequestErr)
  70. return
  71. }
  72. if mid <= 0 || fid <= 0 {
  73. c.JSON(nil, ecode.RequestErr)
  74. return
  75. }
  76. if src, err = strconv.ParseUint(srcStr, 10, 8); err != nil {
  77. c.JSON(nil, ecode.RequestErr)
  78. return
  79. }
  80. ric := infocArg(c)
  81. c.JSON(nil, relationSvc.DelFollowing(c, mid, fid, uint8(src), ric))
  82. }
  83. // delFollowingCache del following cache.
  84. func delFollowingCache(c *bm.Context) {
  85. var (
  86. err error
  87. mid int64
  88. params = c.Request.Form
  89. midStr = params.Get("mid")
  90. )
  91. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  92. c.JSON(nil, ecode.RequestErr)
  93. return
  94. }
  95. c.JSON(nil, relationSvc.DelFollowingCache(c, mid))
  96. }
  97. // updateFollowingCache update following cache.
  98. func updateFollowingCache(c *bm.Context) {
  99. var (
  100. err error
  101. mid, fid int64
  102. na uint64
  103. mts int64
  104. following *model.Following
  105. params = c.Request.Form
  106. midStr = params.Get("mid")
  107. fidStr = params.Get("fid")
  108. naStr = params.Get("attribute")
  109. mtStr = params.Get("mtime")
  110. )
  111. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  112. c.JSON(nil, ecode.RequestErr)
  113. return
  114. }
  115. if fid, err = strconv.ParseInt(fidStr, 10, 64); err != nil {
  116. c.JSON(nil, ecode.RequestErr)
  117. return
  118. }
  119. if na, err = strconv.ParseUint(naStr, 10, 32); err != nil {
  120. c.JSON(nil, ecode.RequestErr)
  121. return
  122. }
  123. if mts, err = strconv.ParseInt(mtStr, 10, 64); err != nil {
  124. c.JSON(nil, ecode.RequestErr)
  125. return
  126. }
  127. following = &model.Following{
  128. Mid: fid,
  129. Attribute: uint32(na),
  130. MTime: time.Time(mts),
  131. }
  132. c.JSON(nil, relationSvc.UpdateFollowingCache(c, mid, following))
  133. }
  134. func sameFollowings(c *bm.Context) {
  135. arg := new(model.ArgSameFollowing)
  136. if err := c.Bind(arg); err != nil {
  137. return
  138. }
  139. c.JSON(relationSvc.SameFollowings(c, arg))
  140. }