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 2.3 KiB

2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/internal/logic/domain/message/service"
  8. "gim/pkg/grpclib"
  9. "gim/pkg/pb"
  10. "strconv"
  11. )
  12. type BusinessExtServer struct{}
  13. func (s *BusinessExtServer) EmoticonList(ctx context.Context, empty *pb.Empty) (*pb.EmoticonListResp, error) {
  14. masterId, err := grpclib.GetCtxMasterId(ctx)
  15. if err != nil {
  16. return nil, err
  17. }
  18. list, err := service.EmoticonList(masterId)
  19. if err != nil {
  20. return nil, err
  21. }
  22. return &pb.EmoticonListResp{Emoticons: list}, err
  23. }
  24. func (s *BusinessExtServer) SignIn(ctx context.Context, req *pb.SignInReq) (*pb.SignInResp, error) {
  25. isNew, userId, token, masterId, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, req.MasterId, req.DeviceId, req.PushAlia)
  26. if err != nil {
  27. return nil, err
  28. }
  29. return &pb.SignInResp{
  30. IsNew: isNew,
  31. UserId: userId,
  32. Token: token,
  33. MasterId: masterId,
  34. }, nil
  35. }
  36. func (s *BusinessExtServer) GetUser(ctx context.Context, req *pb.GetUserReq) (*pb.GetUserResp, error) {
  37. userId, _, err := grpclib.GetCtxData(ctx)
  38. if err != nil {
  39. return nil, err
  40. }
  41. if req.UserId != 0 {
  42. userId = req.UserId
  43. }
  44. user, err := app.UserApp.Get(ctx, userId)
  45. return &pb.GetUserResp{User: user}, err
  46. }
  47. func (s *BusinessExtServer) UpdateUser(ctx context.Context, req *pb.UpdateUserReq) (*pb.Empty, error) {
  48. userId, _, err := grpclib.GetCtxData(ctx)
  49. if err != nil {
  50. return nil, err
  51. }
  52. return new(pb.Empty), app.UserApp.Update(ctx, userId, req)
  53. }
  54. func (s *BusinessExtServer) SearchUser(ctx context.Context, req *pb.SearchUserReq) (*pb.SearchUserResp, error) {
  55. users, err := app.UserApp.Search(ctx, req.Key, req.MasterId)
  56. return &pb.SearchUserResp{Users: users}, err
  57. }
  58. func (s *BusinessExtServer) CloudUploadFile(ctx context.Context, req *pb.CloudUploadFileReq) (*pb.CloudUploadFileResp, error) {
  59. userId, _, err := grpclib.GetCtxData(ctx)
  60. if err != nil {
  61. return nil, err
  62. }
  63. upload, err := comm.CloudUpload.FileReqUpload(ctx, strconv.FormatInt(userId, 10), req.Dir, req.FileName, utils.StrToInt64(req.FileSize))
  64. data := utils.SerializeStr(upload)
  65. var result map[string]string
  66. utils.Unserialize([]byte(data), &result)
  67. return &pb.CloudUploadFileResp{
  68. Method: result["method"],
  69. Host: result["host"],
  70. Key: result["key"],
  71. Token: result["token"],
  72. }, err
  73. }