|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package api
-
- import (
- "context"
- "gim/internal/business/app"
- comm "gim/internal/business/comm"
- "gim/internal/business/comm/utils"
- "gim/pkg/grpclib"
- "gim/pkg/pb"
- "strconv"
- )
-
- type BusinessExtServer struct{}
-
- func (s *BusinessExtServer) SignIn(ctx context.Context, req *pb.SignInReq) (*pb.SignInResp, error) {
- isNew, userId, token, masterId, err := app.AuthApp.SignIn(ctx, req.PhoneNumber, req.Code, req.MasterId, req.DeviceId)
- if err != nil {
- return nil, err
- }
- return &pb.SignInResp{
- IsNew: isNew,
- UserId: userId,
- Token: token,
- MasterId: masterId,
- }, nil
- }
-
- func (s *BusinessExtServer) GetUser(ctx context.Context, req *pb.GetUserReq) (*pb.GetUserResp, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
- if req.UserId != 0 {
- userId = req.UserId
- }
- user, err := app.UserApp.Get(ctx, userId)
- return &pb.GetUserResp{User: user}, err
- }
-
- func (s *BusinessExtServer) UpdateUser(ctx context.Context, req *pb.UpdateUserReq) (*pb.Empty, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- return new(pb.Empty), app.UserApp.Update(ctx, userId, req)
- }
-
- func (s *BusinessExtServer) SearchUser(ctx context.Context, req *pb.SearchUserReq) (*pb.SearchUserResp, error) {
- users, err := app.UserApp.Search(ctx, req.Key, req.MasterId)
- return &pb.SearchUserResp{Users: users}, err
- }
-
- func (s *BusinessExtServer) CloudUploadFile(ctx context.Context, req *pb.CloudUploadFileReq) (*pb.CloudUploadFileResp, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
- upload, err := comm.CloudUpload.FileReqUpload(ctx, strconv.FormatInt(userId, 10), req.Dir, req.FileName, utils.StrToInt64(req.FileSize))
- data := utils.SerializeStr(upload)
- var result map[string]string
- utils.Unserialize([]byte(data), &result)
-
- return &pb.CloudUploadFileResp{
- Method: result["method"],
- Host: result["host"],
- Key: result["key"],
- Token: result["token"],
- }, err
- }
|