golang-im聊天
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

48 lines
1.2 KiB

  1. package api
  2. import (
  3. "context"
  4. "gim/internal/business/app"
  5. "gim/pkg/grpclib"
  6. "gim/pkg/pb"
  7. )
  8. type BusinessExtServer struct{}
  9. func (s *BusinessExtServer) SignIn(ctx context.Context, req *pb.SignInReq) (*pb.SignInResp, error) {
  10. isNew, userId, token, masterId, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, req.MasterId, req.DeviceId)
  11. if err != nil {
  12. return nil, err
  13. }
  14. return &pb.SignInResp{
  15. IsNew: isNew,
  16. UserId: userId,
  17. Token: token,
  18. MasterId: masterId,
  19. }, nil
  20. }
  21. func (s *BusinessExtServer) GetUser(ctx context.Context, req *pb.GetUserReq) (*pb.GetUserResp, error) {
  22. userId, _, err := grpclib.GetCtxData(ctx)
  23. if err != nil {
  24. return nil, err
  25. }
  26. user, err := app.UserApp.Get(ctx, userId)
  27. return &pb.GetUserResp{User: user}, err
  28. }
  29. func (s *BusinessExtServer) UpdateUser(ctx context.Context, req *pb.UpdateUserReq) (*pb.Empty, error) {
  30. userId, _, err := grpclib.GetCtxData(ctx)
  31. if err != nil {
  32. return nil, err
  33. }
  34. return new(pb.Empty), app.UserApp.Update(ctx, userId, req)
  35. }
  36. func (s *BusinessExtServer) SearchUser(ctx context.Context, req *pb.SearchUserReq) (*pb.SearchUserResp, error) {
  37. users, err := app.UserApp.Search(ctx, req.Key, req.MasterId)
  38. return &pb.SearchUserResp{Users: users}, err
  39. }