user_like.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. user "go-common/app/service/bbq/user/api"
  6. "go-common/library/log"
  7. )
  8. // AddLike .
  9. func (d *Dao) AddLike(c context.Context, mid, upMid, svid int64) (affectedNum int64, err error) {
  10. reply, err := d.userClient.AddLike(c, &user.LikeReq{Mid: mid, UpMid: upMid, Opid: svid})
  11. if err != nil {
  12. log.Errorv(c, log.KV("log", fmt.Sprintf("add like fail: mid=%d, up_mid=%d, svid=%d", mid, upMid, svid)))
  13. return
  14. }
  15. affectedNum = reply.AffectedNum
  16. return
  17. }
  18. // CancelLike .
  19. func (d *Dao) CancelLike(c context.Context, mid, upMid, svid int64) (affectedNum int64, err error) {
  20. reply, err := d.userClient.CancelLike(c, &user.LikeReq{Mid: mid, UpMid: upMid, Opid: svid})
  21. if err != nil {
  22. log.Errorv(c, log.KV("log", fmt.Sprintf("cancel like fail: mid=%d, up_mid=%d, svid=%d", mid, upMid, svid)))
  23. return
  24. }
  25. affectedNum = reply.AffectedNum
  26. return
  27. }
  28. // CheckUserLike 检测用户是否点赞
  29. func (d *Dao) CheckUserLike(c context.Context, mid int64, svids []int64) (res map[int64]bool, err error) {
  30. res = make(map[int64]bool)
  31. reply, err := d.userClient.IsLike(c, &user.IsLikeReq{Mid: mid, Svids: svids})
  32. if err != nil {
  33. log.Errorv(c, log.KV("log", "get is like info fail"))
  34. return
  35. }
  36. for _, svid := range reply.List {
  37. res[svid] = true
  38. }
  39. return
  40. }
  41. // UserLikeList .
  42. func (d *Dao) UserLikeList(c context.Context, upMid int64, cursorPrev, cursorNext string) (res *user.ListUserLikeReply, err error) {
  43. res, err = d.userClient.ListUserLike(c, &user.ListUserLikeReq{UpMid: upMid, CursorPrev: cursorPrev, CursorNext: cursorNext})
  44. if err != nil {
  45. log.Errorv(c, log.KV("log", fmt.Sprintf("get user like list fail: up_mid=%d, cursor_prev=%s, next=%s", upMid, cursorPrev, cursorNext)))
  46. return
  47. }
  48. return
  49. }