From 848827482f54456ca45726b6f7c095135b17eee1 Mon Sep 17 00:00:00 2001 From: zetaloop Date: Sat, 25 Apr 2026 08:30:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=89=93=E6=89=8B?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=93=8D=E5=BA=94=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/logic/player/getPlayerLogic.go | 84 +++++++++++++++++-- .../rpc/internal/logic/getPlayersByIdLogic.go | 1 + deploy/dev/test_all_apis.py | 20 ++++- 3 files changed, 96 insertions(+), 9 deletions(-) diff --git a/app/player/api/internal/logic/player/getPlayerLogic.go b/app/player/api/internal/logic/player/getPlayerLogic.go index 1db5992..2a6d460 100644 --- a/app/player/api/internal/logic/player/getPlayerLogic.go +++ b/app/player/api/internal/logic/player/getPlayerLogic.go @@ -5,13 +5,16 @@ package player import ( "context" + "encoding/json" "errors" - "juwan-backend/app/player/rpc/playerservice" + "strconv" + "time" "juwan-backend/app/player/api/internal/svc" "juwan-backend/app/player/api/internal/types" + "juwan-backend/app/player/rpc/playerservice" + "juwan-backend/app/users/rpc/usercenter" - "github.com/jinzhu/copier" "github.com/zeromicro/go-zero/core/logx" ) @@ -31,18 +34,83 @@ func NewGetPlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPlay } func (l *GetPlayerLogic) GetPlayer(req *types.GetPlayerReq) (resp *types.PlayerProfile, err error) { - player, err := l.svcCtx.PlayerRpc.GetPlayersById(l.ctx, &playerservice.GetPlayersByIdReq{ + playerResp, err := l.svcCtx.PlayerRpc.GetPlayersById(l.ctx, &playerservice.GetPlayersByIdReq{ Id: req.Id, }) if err != nil { logx.Errorf("GetPlayerLogic.GetPlayers err: %v", err) return nil, errors.New("failed to get player details") } - resp = &types.PlayerProfile{} - err = copier.Copy(resp, &player) - if err != nil { - logx.Errorf("copier.Copy err: %v", err) - return nil, errors.New("copier.Copy err") + player := playerResp.GetPlayers() + if player == nil { + return nil, errors.New("player not found") } + + resp = &types.PlayerProfile{ + Id: player.Id, + Rating: player.Rating, + TotalOrders: player.TotalOrders, + Status: player.Status, + Gender: player.Gender, + Services: []types.PlayerService{}, + Tags: append([]string{}, player.Tags...), + } + + games := make([]string, 0, len(player.Games)) + for _, gameID := range player.Games { + games = append(games, strconv.FormatInt(gameID, 10)) + } + resp.Games = games + + if player.ShopId != 0 { + resp.ShopId = strconv.FormatInt(player.ShopId, 10) + } + + usersResp, err := l.svcCtx.UserRpc.GetUsersByIds(l.ctx, &usercenter.GetUsersByIdsReq{Ids: []int64{player.UserId}}) + if err != nil { + return nil, err + } + if len(usersResp.Users) > 0 { + u := usersResp.Users[0] + verificationStatus := map[string]string{} + if u.VerificationStatus != "" { + _ = json.Unmarshal([]byte(u.VerificationStatus), &verificationStatus) + } + resp.User = types.UserProfile{ + Id: strconv.FormatInt(u.Id, 10), + Username: u.Username, + Nickname: u.Nickname, + Avatar: u.Avatar, + Role: u.CurrentRole, + VerifiedRoles: append([]string{}, u.VerifiedRoles...), + VerificationStatus: verificationStatus, + Phone: u.Phone, + Bio: u.Bio, + CreatedAt: time.Unix(u.CreatedAt, 0).Format(time.DateTime), + } + } + + svcResp, svcErr := l.svcCtx.PlayerRpc.SearchPlayerServices(l.ctx, &playerservice.SearchPlayerServicesReq{ + PlayerId: player.Id, + Limit: 100, + }) + if svcErr != nil { + logx.Errorf("GetPlayer SearchPlayerServices player=%d err: %v", player.Id, svcErr) + } else { + for _, s := range svcResp.PlayerServices { + resp.Services = append(resp.Services, types.PlayerService{ + Id: s.Id, + PlayerId: s.PlayerId, + GameId: s.GameId, + Title: s.Title, + Description: s.Description, + Price: s.Price, + Unit: s.Unit, + RankRange: s.RankRange, + Availability: s.Availability, + }) + } + } + return } diff --git a/app/player/rpc/internal/logic/getPlayersByIdLogic.go b/app/player/rpc/internal/logic/getPlayersByIdLogic.go index 959bd20..6896eee 100644 --- a/app/player/rpc/internal/logic/getPlayersByIdLogic.go +++ b/app/player/rpc/internal/logic/getPlayersByIdLogic.go @@ -36,6 +36,7 @@ func (l *GetPlayersByIdLogic) GetPlayersById(in *pb.GetPlayersByIdReq) (*pb.GetP Id: player.ID, UserId: player.UserID, Status: player.Status, + Gender: player.Gender, Rating: player.Rating.InexactFloat64(), TotalOrders: int64(player.TotalOrders), CompletedOrders: int64(player.CompletedOrders), diff --git a/deploy/dev/test_all_apis.py b/deploy/dev/test_all_apis.py index 40537b3..5891f6c 100644 --- a/deploy/dev/test_all_apis.py +++ b/deploy/dev/test_all_apis.py @@ -791,7 +791,12 @@ def phase6_player(s: Session, game_id): report(f"GET /players/{player_id}", code, body) report_check( f"GET /players/{player_id} returns initialized online player", - code == 200 and same_id(body.get("id"), player_id) and body.get("status") == "online", + code == 200 + and same_id(body.get("id"), player_id) + and body.get("status") == "online" + and body.get("gender") is True + and as_int((body.get("user") or {}).get("id")) > 0 + and isinstance(body.get("services"), list), body, ) @@ -860,6 +865,19 @@ def phase6_player(s: Session, game_id): body, ) + code, body, _ = s.get(f"{GATEWAY}/api/v1/players/{player_id}") + report(f"GET /players/{player_id} (after service update)", code, body) + service = find_item_by_id(body.get("services") or [], service_id) + report_check( + f"GET /players/{player_id} includes updated service", + code == 200 + and body.get("gender") is True + and bool(service) + and service.get("title") == "Updated Service" + and as_decimal(service.get("price")) == Decimal("60"), + body, + ) + if player_id: code, body, _ = s.get(f"{GATEWAY}/api/v1/players/{player_id}/services") report(f"GET /players/{player_id}/services", code, body)