dao.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package thumbup
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-intl/conf"
  5. thumbup "go-common/app/service/main/thumbup/model"
  6. thumbuprpc "go-common/app/service/main/thumbup/rpc/client"
  7. "go-common/library/net/metadata"
  8. "github.com/pkg/errors"
  9. )
  10. // Dao is tag dao
  11. type Dao struct {
  12. thumbupRPC *thumbuprpc.Service
  13. }
  14. // New initial tag dao
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. thumbupRPC: thumbuprpc.New(c.ThumbupRPC),
  18. }
  19. return
  20. }
  21. // Like is like view.
  22. func (d *Dao) Like(c context.Context, mid, upMid int64, business string, messageID int64, typ int8) (err error) {
  23. ip := metadata.String(c, metadata.RemoteIP)
  24. arg := &thumbup.ArgLike{Mid: mid, UpMid: upMid, Business: business, MessageID: messageID, Type: typ, RealIP: ip}
  25. return d.thumbupRPC.Like(c, arg)
  26. }
  27. // LikeWithStat is like with stat.
  28. func (d *Dao) LikeWithStat(c context.Context, mid, upMid int64, business string, messageID int64, typ int8) (stat *thumbup.Stats, err error) {
  29. ip := metadata.String(c, metadata.RemoteIP)
  30. arg := &thumbup.ArgLike{Mid: mid, UpMid: upMid, Business: business, MessageID: messageID, Type: typ, RealIP: ip}
  31. return d.thumbupRPC.LikeWithStats(c, arg)
  32. }
  33. // HasLike user has like
  34. func (d *Dao) HasLike(c context.Context, mid int64, business string, messageIDs []int64) (res map[int64]int8, err error) {
  35. ip := metadata.String(c, metadata.RemoteIP)
  36. arg := &thumbup.ArgHasLike{Mid: mid, MessageIDs: messageIDs, Business: business, RealIP: ip}
  37. if res, err = d.thumbupRPC.HasLike(c, arg); err != nil {
  38. err = errors.Wrapf(err, "%v", arg)
  39. }
  40. return
  41. }
  42. // Stat is
  43. func (d *Dao) Stat(c context.Context, mid int64, business string, messageIDs []int64) (res map[int64]*thumbup.Stats, err error) {
  44. ip := metadata.String(c, metadata.RemoteIP)
  45. arg := &thumbup.ArgStats{Business: business, MessageIDs: messageIDs, RealIP: ip}
  46. if res, err = d.thumbupRPC.Stats(c, arg); err != nil {
  47. err = errors.Wrapf(err, "%v", arg)
  48. }
  49. return
  50. }