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.

business_ext.go 1.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if req.UserId != 0 {
  30. userId = req.UserId
  31. }
  32. user, err := app.UserApp.Get(ctx, userId)
  33. return &pb.GetUserResp{User: user}, err
  34. }
  35. func (s *BusinessExtServer) UpdateUser(ctx context.Context, req *pb.UpdateUserReq) (*pb.Empty, error) {
  36. userId, _, err := grpclib.GetCtxData(ctx)
  37. if err != nil {
  38. return nil, err
  39. }
  40. return new(pb.Empty), app.UserApp.Update(ctx, userId, req)
  41. }
  42. func (s *BusinessExtServer) SearchUser(ctx context.Context, req *pb.SearchUserReq) (*pb.SearchUserResp, error) {
  43. users, err := app.UserApp.Search(ctx, req.Key, req.MasterId)
  44. return &pb.SearchUserResp{Users: users}, err
  45. }
  46. func (s *BusinessExtServer) CloudUploadFile(ctx context.Context, req *pb.CloudUploadFileReq) (*pb.CloudUploadFileResp, error) {
  47. userId, _, err := grpclib.GetCtxData(ctx)
  48. if err != nil {
  49. return nil, err
  50. }
  51. upload, err := comm.CloudUpload.FileReqUpload(ctx, strconv.FormatInt(userId, 10), req.Dir, req.FileName, utils.StrToInt64(req.FileSize))
  52. data := utils.SerializeStr(upload)
  53. var result map[string]string
  54. utils.Unserialize([]byte(data), &result)
  55. return &pb.CloudUploadFileResp{
  56. Method: result["method"],
  57. Host: result["host"],
  58. Key: result["key"],
  59. Token: result["token"],
  60. }, err
  61. }