user.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. package http
  2. import (
  3. "go-common/app/interface/bbq/app-bbq/api/http/v1"
  4. "go-common/app/interface/bbq/app-bbq/model"
  5. user "go-common/app/service/bbq/user/api"
  6. "go-common/library/ecode"
  7. bm "go-common/library/net/http/blademaster"
  8. "github.com/pkg/errors"
  9. )
  10. //userBase .
  11. func userBase(c *bm.Context) {
  12. mid, exists := c.Get("mid")
  13. if !exists {
  14. c.JSON(nil, ecode.NoLogin)
  15. return
  16. }
  17. c.JSON(srv.UserBase(c, mid.(int64)))
  18. }
  19. //spaceUserProfile ...
  20. func spaceUserProfile(c *bm.Context) {
  21. arg := new(v1.SpaceUserProfileRequest)
  22. mid := int64(0)
  23. midValue, exists := c.Get("mid")
  24. if exists {
  25. mid = midValue.(int64)
  26. }
  27. if err := c.Bind(arg); err != nil {
  28. errors.Wrap(err, "参数验证失败")
  29. return
  30. }
  31. c.JSON(srv.SpaceUserProfile(c, mid, arg.Upmid))
  32. }
  33. //userEdit
  34. func userBaseEdit(c *bm.Context) {
  35. mid, exists := c.Get("mid")
  36. if !exists {
  37. c.JSON(nil, ecode.NoLogin)
  38. return
  39. }
  40. arg := new(user.UserBase)
  41. if err := c.Bind(arg); err != nil {
  42. errors.Wrap(err, "参数验证失败")
  43. return
  44. }
  45. arg.Mid = mid.(int64)
  46. c.JSON(srv.UserEdit(c, arg))
  47. }
  48. //addUserLike .
  49. func addUserLike(c *bm.Context) {
  50. mid, exists := c.Get("mid")
  51. if !exists {
  52. c.JSON(nil, ecode.NoLogin)
  53. return
  54. }
  55. arg := new(v1.UserLikeAddRequest)
  56. if err := c.Bind(arg); err != nil {
  57. errors.Wrap(err, "参数验证失败")
  58. return
  59. }
  60. resp, err := srv.AddUserLike(c, mid.(int64), arg.SVID)
  61. c.JSON(resp, err)
  62. // 埋点
  63. if err == nil {
  64. uiLog(c, model.ActionLike, nil)
  65. }
  66. }
  67. //cancelUserLike .
  68. func cancelUserLike(c *bm.Context) {
  69. mid, exists := c.Get("mid")
  70. if !exists {
  71. c.JSON(nil, ecode.NoLogin)
  72. return
  73. }
  74. arg := new(v1.UserLikeCancelRequest)
  75. if err := c.Bind(arg); err != nil {
  76. errors.Wrap(err, "参数验证失败")
  77. return
  78. }
  79. resp, err := srv.CancelUserLike(c, mid.(int64), arg.SVID)
  80. c.JSON(resp, err)
  81. // 埋点
  82. if err == nil {
  83. uiLog(c, model.ActionCancelLike, nil)
  84. }
  85. }
  86. //userLikeList .
  87. func userLikeList(c *bm.Context) {
  88. arg := &v1.SpaceSvListRequest{}
  89. if err := c.Bind(arg); err != nil {
  90. errors.Wrap(err, "参数验证失败")
  91. return
  92. }
  93. mid, exists := c.Get("mid")
  94. if exists {
  95. arg.MID = mid.(int64)
  96. }
  97. dev, _ := c.Get("device")
  98. arg.Device = dev.(*bm.Device)
  99. arg.Size = model.SpaceListLen
  100. c.JSON(srv.UserLikeList(c, arg))
  101. }
  102. //userFollowList .
  103. func userFollowList(c *bm.Context) {
  104. arg := new(user.ListRelationUserInfoReq)
  105. mid, exists := c.Get("mid")
  106. if exists {
  107. arg.Mid = mid.(int64)
  108. }
  109. if err := c.Bind(arg); err != nil {
  110. errors.Wrap(err, "参数验证失败")
  111. return
  112. }
  113. c.JSON(srv.UserFollowList(c, arg))
  114. }
  115. //userFanList .
  116. func userFanList(c *bm.Context) {
  117. arg := new(user.ListRelationUserInfoReq)
  118. mid, exists := c.Get("mid")
  119. if exists {
  120. arg.Mid = mid.(int64)
  121. }
  122. if err := c.Bind(arg); err != nil {
  123. errors.Wrap(err, "参数验证失败")
  124. return
  125. }
  126. c.JSON(srv.UserFanList(c, arg))
  127. }
  128. //userBlackList .
  129. func userBlackList(c *bm.Context) {
  130. arg := new(user.ListRelationUserInfoReq)
  131. mid, exists := c.Get("mid")
  132. if exists {
  133. arg.Mid = mid.(int64)
  134. }
  135. if err := c.Bind(arg); err != nil {
  136. errors.Wrap(err, "参数验证失败")
  137. return
  138. }
  139. c.JSON(srv.UserBlackList(c, arg))
  140. }
  141. //userRelationModify .
  142. func userRelationModify(c *bm.Context) {
  143. mid, exists := c.Get("mid")
  144. if !exists {
  145. c.JSON(nil, ecode.NoLogin)
  146. return
  147. }
  148. arg := new(v1.UserRelationRequest)
  149. if err := c.Bind(arg); err != nil {
  150. errors.Wrap(err, "参数验证失败")
  151. return
  152. }
  153. var reportAction int
  154. switch arg.Action {
  155. case user.FollowAdd:
  156. reportAction = model.ActionFollow
  157. case user.FollowCancel:
  158. reportAction = model.ActionCancelFollow
  159. case user.BlackAdd:
  160. reportAction = model.ActionBlack
  161. case user.BlackCancel:
  162. reportAction = model.ActionCancelBlack
  163. default:
  164. errors.Wrap(ecode.ReqParamErr, "参数验证失败")
  165. return
  166. }
  167. res, err := srv.ModifyRelation(c, mid.(int64), arg.UPMID, arg.Action)
  168. c.JSON(res, err)
  169. // 埋点
  170. if err == nil && reportAction != 0 {
  171. ext := struct {
  172. UPMID int64 `json:"up_mid"`
  173. }{
  174. UPMID: arg.UPMID,
  175. }
  176. uiLog(c, reportAction, ext)
  177. }
  178. }
  179. //login 登陆
  180. func login(c *bm.Context) {
  181. arg := new(user.UserBase)
  182. mid, exists := c.Get("mid")
  183. if !exists {
  184. c.JSON(nil, ecode.NoLogin)
  185. return
  186. }
  187. if err := c.Bind(arg); err != nil {
  188. errors.Wrap(err, "参数验证失败")
  189. return
  190. }
  191. arg.Mid = mid.(int64)
  192. c.JSON(srv.Login(c, arg))
  193. }
  194. // userUnLike 不感兴趣
  195. func userUnLike(c *bm.Context) {
  196. tmp, exists := c.Get("mid")
  197. if !exists || tmp == nil {
  198. c.JSON(nil, ecode.NoLogin)
  199. return
  200. }
  201. arg := new(v1.UnLikeReq)
  202. if err := c.Bind(arg); err != nil {
  203. return
  204. }
  205. arg.MID = tmp.(int64)
  206. c.JSON(new(interface{}), nil)
  207. // 埋点
  208. uiLog(c, model.ActionUserUnLike, arg)
  209. }