fix: 修复打手详情响应字段
This commit is contained in:
@@ -5,13 +5,16 @@ package player
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"juwan-backend/app/player/rpc/playerservice"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"juwan-backend/app/player/api/internal/svc"
|
"juwan-backend/app/player/api/internal/svc"
|
||||||
"juwan-backend/app/player/api/internal/types"
|
"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"
|
"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) {
|
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,
|
Id: req.Id,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Errorf("GetPlayerLogic.GetPlayers err: %v", err)
|
logx.Errorf("GetPlayerLogic.GetPlayers err: %v", err)
|
||||||
return nil, errors.New("failed to get player details")
|
return nil, errors.New("failed to get player details")
|
||||||
}
|
}
|
||||||
resp = &types.PlayerProfile{}
|
player := playerResp.GetPlayers()
|
||||||
err = copier.Copy(resp, &player)
|
if player == nil {
|
||||||
if err != nil {
|
return nil, errors.New("player not found")
|
||||||
logx.Errorf("copier.Copy err: %v", err)
|
|
||||||
return nil, errors.New("copier.Copy err")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ func (l *GetPlayersByIdLogic) GetPlayersById(in *pb.GetPlayersByIdReq) (*pb.GetP
|
|||||||
Id: player.ID,
|
Id: player.ID,
|
||||||
UserId: player.UserID,
|
UserId: player.UserID,
|
||||||
Status: player.Status,
|
Status: player.Status,
|
||||||
|
Gender: player.Gender,
|
||||||
Rating: player.Rating.InexactFloat64(),
|
Rating: player.Rating.InexactFloat64(),
|
||||||
TotalOrders: int64(player.TotalOrders),
|
TotalOrders: int64(player.TotalOrders),
|
||||||
CompletedOrders: int64(player.CompletedOrders),
|
CompletedOrders: int64(player.CompletedOrders),
|
||||||
|
|||||||
@@ -791,7 +791,12 @@ def phase6_player(s: Session, game_id):
|
|||||||
report(f"GET /players/{player_id}", code, body)
|
report(f"GET /players/{player_id}", code, body)
|
||||||
report_check(
|
report_check(
|
||||||
f"GET /players/{player_id} returns initialized online player",
|
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,
|
body,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -860,6 +865,19 @@ def phase6_player(s: Session, game_id):
|
|||||||
body,
|
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:
|
if player_id:
|
||||||
code, body, _ = s.get(f"{GATEWAY}/api/v1/players/{player_id}/services")
|
code, body, _ = s.get(f"{GATEWAY}/api/v1/players/{player_id}/services")
|
||||||
report(f"GET /players/{player_id}/services", code, body)
|
report(f"GET /players/{player_id}/services", code, body)
|
||||||
|
|||||||
Reference in New Issue
Block a user