user_relation.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/interface/bbq/app-bbq/api/http/v1"
  6. user "go-common/app/service/bbq/user/api"
  7. "go-common/library/log"
  8. )
  9. // ModifyRelation .
  10. func (d *Dao) ModifyRelation(c context.Context, mid, upMid int64, action int32) (res *user.ModifyRelationReply, err error) {
  11. res, err = d.userClient.ModifyRelation(c, &user.ModifyRelationReq{Mid: mid, UpMid: upMid, Action: action})
  12. if err != nil {
  13. log.Errorv(c, log.KV("log", fmt.Sprintf("modify relation fail: mid=%d, up_mid=%d, action=%d", mid, upMid, action)))
  14. }
  15. return
  16. }
  17. // UserRelationList .
  18. func (d *Dao) UserRelationList(c context.Context, userReq *user.ListRelationUserInfoReq, relationType int32) (res *v1.UserRelationListResponse, err error) {
  19. res = new(v1.UserRelationListResponse)
  20. var reply *user.ListUserInfoReply
  21. switch relationType {
  22. case user.Follow:
  23. reply, err = d.userClient.ListFollowUserInfo(c, userReq)
  24. case user.Fan:
  25. reply, err = d.userClient.ListFanUserInfo(c, userReq)
  26. case user.Black:
  27. reply, err = d.userClient.ListBlackUserInfo(c, userReq)
  28. }
  29. if err != nil {
  30. log.Errorv(c, log.KV("log", fmt.Sprintf("user relation list fail: req=%s", userReq.String())))
  31. return
  32. }
  33. res.HasMore = reply.HasMore
  34. for _, v := range reply.List {
  35. userInfo := &v1.UserInfo{UserBase: *v.UserBase, FollowState: v.FollowState, CursorValue: v.CursorValue}
  36. res.List = append(res.List, userInfo)
  37. }
  38. return
  39. }
  40. // FetchFollowList 获取mid的所有关注up主
  41. func (d *Dao) FetchFollowList(c context.Context, mid int64) (upMid []int64, err error) {
  42. res, err := d.userClient.ListFollow(c, &user.ListRelationReq{Mid: mid})
  43. if err != nil {
  44. log.Errorv(c, log.KV("log", "fetch follow list fail"))
  45. return
  46. }
  47. upMid = res.List
  48. return
  49. }