thumbup.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package client
  2. import (
  3. "context"
  4. "go-common/app/service/main/thumbup/model"
  5. "go-common/library/net/rpc"
  6. )
  7. const (
  8. _like = "RPC.Like"
  9. _likeWithStats = "RPC.LikeWithStats"
  10. _hasLike = "RPC.HasLike"
  11. _stats = "RPC.Stats"
  12. _userLikes = "RPC.UserLikes"
  13. _userDislikes = "RPC.UserDislikes"
  14. _itemLikes = "RPC.ItemLikes"
  15. _itemDislikes = "RPC.ItemDislikes"
  16. _statsWithLike = "RPC.StatsWithLike"
  17. _userTotalLike = "RPC.UserTotalLike"
  18. _updateCount = "RPC.UpdateCount"
  19. _rawStats = "RPC.RawStats"
  20. )
  21. const (
  22. _appid = "community.service.thumbup"
  23. )
  24. var (
  25. // _noArg = &struct{}{}
  26. _noReply = &struct{}{}
  27. )
  28. //go:generate mockgen -source thumbup.go -destination mock.go -package client
  29. // ThumbupRPC rpc interface
  30. type ThumbupRPC interface {
  31. Like(c context.Context, arg *model.ArgLike) (err error)
  32. HasLike(c context.Context, arg *model.ArgHasLike) (res map[int64]int8, err error)
  33. Stats(c context.Context, arg *model.ArgStats) (res map[int64]*model.Stats, err error)
  34. UserLikes(c context.Context, arg *model.ArgUserLikes) (res []*model.ItemLikeRecord, err error)
  35. UserDislikes(c context.Context, arg *model.ArgUserLikes) (res []*model.ItemLikeRecord, err error)
  36. ItemLikes(c context.Context, arg *model.ArgItemLikes) (res []*model.UserLikeRecord, err error)
  37. ItemDislikes(c context.Context, arg *model.ArgItemLikes) (res []*model.UserLikeRecord, err error)
  38. StatsWithLike(c context.Context, arg *model.ArgStatsWithLike) (res map[int64]*model.StatsWithLike, err error)
  39. UserTotalLike(c context.Context, arg *model.ArgUserLikes) (res *model.UserTotalLike, err error)
  40. }
  41. // Service struct info.
  42. type Service struct {
  43. client *rpc.Client2
  44. }
  45. // New new service instance and return.
  46. func New(c *rpc.ClientConfig) (s *Service) {
  47. s = &Service{}
  48. s.client = rpc.NewDiscoveryCli(_appid, c)
  49. return
  50. }
  51. // Like add like/dislike
  52. func (s *Service) Like(c context.Context, arg *model.ArgLike) (err error) {
  53. err = s.client.Call(c, _like, arg, _noReply)
  54. return
  55. }
  56. // LikeWithStats add like/dislike and return the stats info
  57. func (s *Service) LikeWithStats(ctx context.Context, arg *model.ArgLike) (res *model.Stats, err error) {
  58. err = s.client.Call(ctx, _likeWithStats, arg, &res)
  59. return
  60. }
  61. // HasLike query user has liked something
  62. func (s *Service) HasLike(c context.Context, arg *model.ArgHasLike) (res map[int64]int8, err error) {
  63. err = s.client.Call(c, _hasLike, arg, &res)
  64. return
  65. }
  66. // Stats return stats message
  67. func (s *Service) Stats(c context.Context, arg *model.ArgStats) (res map[int64]*model.Stats, err error) {
  68. err = s.client.Call(c, _stats, arg, &res)
  69. return
  70. }
  71. // UserLikes user likes list
  72. func (s *Service) UserLikes(c context.Context, arg *model.ArgUserLikes) (res []*model.ItemLikeRecord, err error) {
  73. err = s.client.Call(c, _userLikes, arg, &res)
  74. return
  75. }
  76. // UserDislikes user dislikes list
  77. func (s *Service) UserDislikes(c context.Context, arg *model.ArgUserLikes) (res []*model.ItemLikeRecord, err error) {
  78. err = s.client.Call(c, _userDislikes, arg, &res)
  79. return
  80. }
  81. // ItemLikes item likes list
  82. func (s *Service) ItemLikes(c context.Context, arg *model.ArgItemLikes) (res []*model.UserLikeRecord, err error) {
  83. err = s.client.Call(c, _itemLikes, arg, &res)
  84. return
  85. }
  86. // ItemDislikes item dislikes list
  87. func (s *Service) ItemDislikes(c context.Context, arg *model.ArgItemLikes) (res []*model.UserLikeRecord, err error) {
  88. err = s.client.Call(c, _itemDislikes, arg, &res)
  89. return
  90. }
  91. // StatsWithLike return stats and like state
  92. func (s *Service) StatsWithLike(c context.Context, arg *model.ArgStatsWithLike) (res map[int64]*model.StatsWithLike, err error) {
  93. err = s.client.Call(c, _statsWithLike, arg, &res)
  94. return
  95. }
  96. // UserTotalLike user item list with total count
  97. func (s *Service) UserTotalLike(c context.Context, arg *model.ArgUserLikes) (res *model.UserTotalLike, err error) {
  98. err = s.client.Call(c, _userTotalLike, arg, &res)
  99. return
  100. }
  101. // UpdateCount update count
  102. func (s *Service) UpdateCount(c context.Context, arg *model.ArgUpdateCount) (err error) {
  103. err = s.client.Call(c, _updateCount, arg, _noReply)
  104. return
  105. }
  106. // RawStats get stat changes
  107. func (s *Service) RawStats(c context.Context, arg *model.ArgRawStats) (res model.RawStats, err error) {
  108. err = s.client.Call(c, _rawStats, arg, &res)
  109. return
  110. }