golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 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, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, 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. }, nil
  19. }
  20. func (s *BusinessExtServer) GetUser(ctx context.Context, req *pb.GetUserReq) (*pb.GetUserResp, error) {
  21. userId, _, err := grpclib.GetCtxData(ctx)
  22. if err != nil {
  23. return nil, err
  24. }
  25. user, err := app.UserApp.Get(ctx, userId)
  26. return &pb.GetUserResp{User: user}, err
  27. }
  28. func (s *BusinessExtServer) UpdateUser(ctx context.Context, req *pb.UpdateUserReq) (*pb.Empty, error) {
  29. userId, _, err := grpclib.GetCtxData(ctx)
  30. if err != nil {
  31. return nil, err
  32. }
  33. return new(pb.Empty), app.UserApp.Update(ctx, userId, req)
  34. }
  35. func (s *BusinessExtServer) SearchUser(ctx context.Context, req *pb.SearchUserReq) (*pb.SearchUserResp, error) {
  36. users, err := app.UserApp.Search(ctx, req.Key)
  37. return &pb.SearchUserResp{Users: users}, err
  38. }