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.
 
 
 
 

69 lines
1.9 KiB

  1. package api
  2. import (
  3. "context"
  4. "gim/internal/business/app"
  5. comm "gim/internal/business/comm"
  6. "gim/internal/business/comm/utils"
  7. "gim/pkg/grpclib"
  8. "gim/pkg/pb"
  9. "strconv"
  10. )
  11. type BusinessExtServer struct{}
  12. func (s *BusinessExtServer) SignIn(ctx context.Context, req *pb.SignInReq) (*pb.SignInResp, error) {
  13. isNew, userId, token, masterId, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, req.MasterId, req.DeviceId)
  14. if err != nil {
  15. return nil, err
  16. }
  17. return &pb.SignInResp{
  18. IsNew: isNew,
  19. UserId: userId,
  20. Token: token,
  21. MasterId: masterId,
  22. }, nil
  23. }
  24. func (s *BusinessExtServer) GetUser(ctx context.Context, req *pb.GetUserReq) (*pb.GetUserResp, error) {
  25. userId, _, err := grpclib.GetCtxData(ctx)
  26. if err != nil {
  27. return nil, err
  28. }
  29. user, err := app.UserApp.Get(ctx, userId)
  30. return &pb.GetUserResp{User: user}, err
  31. }
  32. func (s *BusinessExtServer) UpdateUser(ctx context.Context, req *pb.UpdateUserReq) (*pb.Empty, error) {
  33. userId, _, err := grpclib.GetCtxData(ctx)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return new(pb.Empty), app.UserApp.Update(ctx, userId, req)
  38. }
  39. func (s *BusinessExtServer) SearchUser(ctx context.Context, req *pb.SearchUserReq) (*pb.SearchUserResp, error) {
  40. users, err := app.UserApp.Search(ctx, req.Key, req.MasterId)
  41. return &pb.SearchUserResp{Users: users}, err
  42. }
  43. func (s *BusinessExtServer) CloudUploadFile(ctx context.Context, req *pb.CloudUploadFileReq) (*pb.CloudUploadFileResp, error) {
  44. userId, _, err := grpclib.GetCtxData(ctx)
  45. if err != nil {
  46. return nil, err
  47. }
  48. upload, err := comm.CloudUpload.FileReqUpload(ctx, strconv.FormatInt(userId, 10), req.Dir, req.FileName, utils.StrToInt64(req.FileSize))
  49. data := utils.SerializeStr(upload)
  50. var result map[string]string
  51. utils.Unserialize([]byte(data), &result)
  52. return &pb.CloudUploadFileResp{
  53. Method: result["method"],
  54. Host: result["host"],
  55. Key: result["key"],
  56. Token: result["token"],
  57. }, err
  58. }