dao.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package relation
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-interface/conf"
  5. relation "go-common/app/service/main/relation/model"
  6. relationrpc "go-common/app/service/main/relation/rpc/client"
  7. "go-common/library/net/metadata"
  8. "github.com/pkg/errors"
  9. )
  10. type Dao struct {
  11. relationRPC *relationrpc.Service
  12. }
  13. func New(c *conf.Config) (d *Dao) {
  14. d = &Dao{
  15. relationRPC: relationrpc.New(c.RelationRPC),
  16. }
  17. return
  18. }
  19. // Stat get mid relation stat
  20. func (d *Dao) Stat(c context.Context, mid int64) (stat *relation.Stat, err error) {
  21. stat, err = d.relationRPC.Stat(c, &relation.ArgMid{Mid: mid})
  22. if err != nil {
  23. err = errors.Wrapf(err, "%v", mid)
  24. }
  25. return
  26. }
  27. func (d *Dao) FollowersUnread(c context.Context, vmid int64) (res bool, err error) {
  28. ip := metadata.String(c, metadata.RemoteIP)
  29. arg := &relation.ArgMid{Mid: vmid, RealIP: ip}
  30. if res, err = d.relationRPC.FollowersUnread(c, arg); err != nil {
  31. err = errors.Wrapf(err, "%v", arg)
  32. }
  33. return
  34. }
  35. func (d *Dao) Followings(c context.Context, vmid int64) (res []*relation.Following, err error) {
  36. ip := metadata.String(c, metadata.RemoteIP)
  37. arg := &relation.ArgMid{Mid: vmid, RealIP: ip}
  38. if res, err = d.relationRPC.Followings(c, arg); err != nil {
  39. err = errors.Wrapf(err, "%v", arg)
  40. }
  41. return
  42. }
  43. func (d *Dao) Relations(c context.Context, mid int64, fids []int64) (res map[int64]*relation.Following, err error) {
  44. ip := metadata.String(c, metadata.RemoteIP)
  45. arg := &relation.ArgRelations{Mid: mid, Fids: fids, RealIP: ip}
  46. if res, err = d.relationRPC.Relations(c, arg); err != nil {
  47. err = errors.Wrapf(err, "%v", arg)
  48. }
  49. return
  50. }
  51. func (d *Dao) Tag(c context.Context, mid, tid int64) (res []int64, err error) {
  52. ip := metadata.String(c, metadata.RemoteIP)
  53. arg := &relation.ArgTagId{Mid: mid, TagId: tid, RealIP: ip}
  54. if res, err = d.relationRPC.Tag(c, arg); err != nil {
  55. err = errors.Wrapf(err, "%v", arg)
  56. }
  57. return
  58. }
  59. func (d *Dao) FollowersUnreadCount(c context.Context, mid int64) (res int64, err error) {
  60. ip := metadata.String(c, metadata.RemoteIP)
  61. arg := &relation.ArgMid{Mid: mid, RealIP: ip}
  62. if res, err = d.relationRPC.FollowersUnreadCount(c, arg); err != nil {
  63. err = errors.Wrapf(err, "%v", arg)
  64. }
  65. return
  66. }