|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package api
-
- import (
- "context"
- "errors"
- "gim/internal/business/app"
- comm "gim/internal/business/comm"
- "gim/internal/business/comm/utils"
- "gim/internal/business/domain/user/repo"
- friend2 "gim/internal/logic/domain/friend"
- "gim/internal/logic/domain/message/service"
- "gim/pkg/grpclib"
- "gim/pkg/pb"
- "strconv"
- )
-
- type BusinessExtServer struct{}
-
- func (s *BusinessExtServer) IsFriends(ctx context.Context, req *pb.IsFriendsReq) (*pb.IsFriendsResp, error) {
- masterId, err := grpclib.GetCtxMasterId(ctx)
- if err != nil {
- return nil, err
- }
- user, err := repo.UserRepo.GetByPhoneNumber(req.UserPhone, utils.StrToInt64(masterId))
- if err != nil {
- return nil, err
- }
- if user == nil {
- return nil, errors.New("未查询到自身用户信息")
- }
-
- userFriend, err := repo.UserRepo.GetByPhoneNumber(req.FriendPhone, utils.StrToInt64(masterId))
- if err != nil {
- return nil, err
- }
- if userFriend == nil {
- return nil, errors.New("未查询到好友用户信息")
- }
- friend, err := friend2.FriendRepo.Get(user.Id, userFriend.Id)
- if err != nil {
- return nil, err
- }
- var isFriend = int64(1)
- if friend == nil {
- isFriend = 2
- }
-
- return &pb.IsFriendsResp{
- User: &pb.User{
- UserId: userFriend.Id,
- Nickname: userFriend.Nickname,
- Sex: userFriend.Sex,
- AvatarUrl: userFriend.AvatarUrl,
- MasterId: userFriend.MasterId,
- IsAutoAddedFriends: int64(userFriend.IsAutoAddedFriends),
- },
- IsFriend: isFriend,
- }, err
- }
-
- func (s *BusinessExtServer) EmoticonList(ctx context.Context, empty *pb.Empty) (*pb.EmoticonListResp, error) {
- masterId, err := grpclib.GetCtxMasterId(ctx)
- if err != nil {
- return nil, err
- }
- list, err := service.EmoticonList(masterId)
- if err != nil {
- return nil, err
- }
-
- return &pb.EmoticonListResp{Emoticons: list}, err
- }
-
- 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, req.PushAlia)
- 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) {
- var user *pb.User
- var err error
- if req.Phone != "" {
- masterId, err := grpclib.GetCtxMasterId(ctx)
- if err != nil {
- return nil, err
- }
- useInfo, err := repo.UserRepo.GetByPhoneNumber(req.Phone, utils.StrToInt64(masterId))
- user = &pb.User{
- UserId: useInfo.Id,
- Nickname: useInfo.Nickname,
- Sex: useInfo.Sex,
- AvatarUrl: useInfo.AvatarUrl,
- MasterId: useInfo.MasterId,
- IsAutoAddedFriends: int64(useInfo.IsAutoAddedFriends),
- }
- } else {
- 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
- }
|