dao.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package relation
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-view/conf"
  5. relation "go-common/app/service/main/relation/model"
  6. relrpc "go-common/app/service/main/relation/rpc/client"
  7. "github.com/pkg/errors"
  8. )
  9. type Dao struct {
  10. relationRPC *relrpc.Service
  11. }
  12. func New(c *conf.Config) (d *Dao) {
  13. d = &Dao{
  14. relationRPC: relrpc.New(c.RelationRPC),
  15. }
  16. return
  17. }
  18. // Prompt prompt
  19. func (d *Dao) Prompt(c context.Context, mid, vmid int64, btype int8) (prompt bool, err error) {
  20. arg := &relation.ArgPrompt{Mid: mid, Fid: vmid, Btype: btype}
  21. if prompt, err = d.relationRPC.Prompt(c, arg); err != nil {
  22. err = errors.Wrapf(err, "%v", arg)
  23. }
  24. return
  25. }
  26. // Stat stat
  27. func (d *Dao) Stat(c context.Context, mid int64) (stat *relation.Stat, err error) {
  28. if stat, err = d.relationRPC.Stat(c, &relation.ArgMid{Mid: mid}); err != nil {
  29. err = errors.Wrapf(err, "%v", mid)
  30. }
  31. return
  32. }
  33. // Stats fids stats
  34. func (d *Dao) Stats(ctx context.Context, mids []int64) (res map[int64]*relation.Stat, err error) {
  35. arg := &relation.ArgMids{Mids: mids}
  36. if res, err = d.relationRPC.Stats(ctx, arg); err != nil {
  37. err = errors.Wrapf(err, "%v", arg)
  38. }
  39. return
  40. }