member.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. package grpc
  2. import (
  3. "context"
  4. "go-common/app/service/main/member/api"
  5. "go-common/app/service/main/member/service"
  6. "go-common/app/service/main/member/service/block"
  7. "go-common/library/net/rpc/warden"
  8. )
  9. // New Member warden rpc server
  10. func New(cfg *warden.ServerConfig, s *service.Service) *warden.Server {
  11. w := warden.NewServer(cfg)
  12. api.RegisterMemberServer(w.Server(), &MemberServer{svr: s, blockSvr: s.BlockImpl()})
  13. ws, err := w.Start()
  14. if err != nil {
  15. panic(err)
  16. }
  17. return ws
  18. }
  19. // MemberServer define member Service
  20. type MemberServer struct {
  21. svr *service.Service
  22. blockSvr *block.Service
  23. }
  24. var _ api.MemberServer = &MemberServer{}
  25. // Base get member base info
  26. func (s *MemberServer) Base(ctx context.Context, req *api.MemberMidReq) (*api.BaseInfoReply, error) {
  27. res, err := s.svr.BaseInfo(ctx, req.Mid)
  28. if err != nil {
  29. return nil, err
  30. }
  31. return api.FromBaseInfo(res), nil
  32. }
  33. // Bases batch get members base info
  34. func (s *MemberServer) Bases(ctx context.Context, req *api.MemberMidsReq) (*api.BaseInfosReply, error) {
  35. res, err := s.svr.BatchBaseInfo(ctx, req.Mids)
  36. if err != nil {
  37. return nil, err
  38. }
  39. baseInfos := make(map[int64]*api.BaseInfoReply, len(res))
  40. baseInfosReply := &api.BaseInfosReply{
  41. BaseInfos: baseInfos,
  42. }
  43. for k, v := range res {
  44. baseInfos[k] = api.FromBaseInfo(v)
  45. }
  46. return baseInfosReply, nil
  47. }
  48. // Member get member full information
  49. func (s *MemberServer) Member(ctx context.Context, req *api.MemberMidReq) (*api.MemberInfoReply, error) {
  50. res, err := s.svr.Member(ctx, req.Mid)
  51. if err != nil {
  52. return nil, err
  53. }
  54. memberInfoReply := api.FromMember(res)
  55. return memberInfoReply, nil
  56. }
  57. // Members Batch get members info
  58. func (s *MemberServer) Members(ctx context.Context, req *api.MemberMidsReq) (*api.MemberInfosReply, error) {
  59. res, err := s.svr.Members(ctx, req.Mids)
  60. if err != nil {
  61. return nil, err
  62. }
  63. memberInfos := make(map[int64]*api.MemberInfoReply, len(res))
  64. for k, v := range res {
  65. memberInfoReply := api.FromMember(v)
  66. memberInfos[k] = memberInfoReply
  67. }
  68. memberInfosReply := &api.MemberInfosReply{
  69. MemberInfos: memberInfos,
  70. }
  71. return memberInfosReply, nil
  72. }
  73. // NickUpdated Whether the member's nickname has been updated
  74. func (s *MemberServer) NickUpdated(ctx context.Context, req *api.MemberMidReq) (*api.NickUpdatedReply, error) {
  75. res, err := s.svr.NickUpdated(ctx, req.Mid)
  76. if err != nil {
  77. return nil, err
  78. }
  79. nickUpdatedReply := &api.NickUpdatedReply{
  80. NickUpdated: res,
  81. }
  82. return nickUpdatedReply, nil
  83. }
  84. // SetNickUpdated Mark nickname as updated
  85. func (s *MemberServer) SetNickUpdated(ctx context.Context, req *api.MemberMidReq) (*api.EmptyStruct, error) {
  86. err := s.svr.SetNickUpdated(ctx, req.Mid)
  87. if err != nil {
  88. return nil, err
  89. }
  90. emptyStruct := &api.EmptyStruct{}
  91. return emptyStruct, nil
  92. }
  93. // SetOfficialDoc Set offical document
  94. func (s *MemberServer) SetOfficialDoc(ctx context.Context, req *api.OfficialDocReq) (*api.EmptyStruct, error) {
  95. err := s.svr.SetOfficialDoc(ctx, api.ToArgOfficialDoc(req))
  96. if err != nil {
  97. return nil, err
  98. }
  99. emptyStruct := &api.EmptyStruct{}
  100. return emptyStruct, nil
  101. }
  102. // SetSex Set member's sex
  103. func (s *MemberServer) SetSex(ctx context.Context, req *api.UpdateSexReq) (*api.EmptyStruct, error) {
  104. err := s.svr.SetSex(ctx, req.Mid, req.Sex)
  105. if err != nil {
  106. return nil, err
  107. }
  108. emptyStruct := &api.EmptyStruct{}
  109. return emptyStruct, nil
  110. }
  111. // SetName Set member's name
  112. func (s *MemberServer) SetName(ctx context.Context, req *api.UpdateUnameReq) (*api.EmptyStruct, error) {
  113. err := s.svr.SetName(ctx, req.Mid, req.Name)
  114. if err != nil {
  115. return nil, err
  116. }
  117. emptyStruct := &api.EmptyStruct{}
  118. return emptyStruct, nil
  119. }
  120. // SetFace Set member's face
  121. func (s *MemberServer) SetFace(ctx context.Context, req *api.UpdateFaceReq) (*api.EmptyStruct, error) {
  122. err := s.svr.SetFace(ctx, req.Mid, req.Face)
  123. if err != nil {
  124. return nil, err
  125. }
  126. emptyStruct := &api.EmptyStruct{}
  127. return emptyStruct, nil
  128. }
  129. // SetRank Set member's rank
  130. func (s *MemberServer) SetRank(ctx context.Context, req *api.UpdateRankReq) (*api.EmptyStruct, error) {
  131. err := s.svr.SetRank(ctx, req.Mid, req.Rank)
  132. if err != nil {
  133. return nil, err
  134. }
  135. emptyStruct := &api.EmptyStruct{}
  136. return emptyStruct, nil
  137. }
  138. // SetBirthday Set member's birthday
  139. func (s *MemberServer) SetBirthday(ctx context.Context, req *api.UpdateBirthdayReq) (*api.EmptyStruct, error) {
  140. err := s.svr.SetBirthday(ctx, req.Mid, req.Birthday)
  141. if err != nil {
  142. return nil, err
  143. }
  144. emptyStruct := &api.EmptyStruct{}
  145. return emptyStruct, nil
  146. }
  147. // SetSign Set member's sign
  148. func (s *MemberServer) SetSign(ctx context.Context, req *api.UpdateSignReq) (*api.EmptyStruct, error) {
  149. err := s.svr.SetSign(ctx, req.Mid, req.Sign)
  150. if err != nil {
  151. return nil, err
  152. }
  153. emptyStruct := &api.EmptyStruct{}
  154. return emptyStruct, nil
  155. }
  156. // OfficialDoc Get member's offical doc
  157. func (s *MemberServer) OfficialDoc(ctx context.Context, req *api.MidReq) (*api.OfficialDocInfoReply, error) {
  158. res, err := s.svr.OfficialDoc(ctx, req.Mid)
  159. if err != nil {
  160. return nil, err
  161. }
  162. officialDocInfoReply := api.FromOfficialDoc(res)
  163. return officialDocInfoReply, nil
  164. }