fix: 打手自操作改为查找打手身份
This commit is contained in:
@@ -7,11 +7,13 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/player/rpc/playerservice"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"juwan-backend/app/player/api/internal/svc"
|
||||
"juwan-backend/app/player/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type CreateServiceLogic struct {
|
||||
@@ -30,8 +32,28 @@ func NewCreateServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
|
||||
}
|
||||
|
||||
func (l *CreateServiceLogic) CreateService(req *types.CreateServiceReq) (resp *types.PlayerService, err error) {
|
||||
_, err = l.svcCtx.PlayerRpc.AddPlayerServices(l.ctx, &playerservice.AddPlayerServicesReq{
|
||||
userID, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
playerResp, err := l.svcCtx.PlayerRpc.GetPlayerByUserId(l.ctx, &playerservice.SearchPlayersReq{UserId: &userID})
|
||||
if err != nil {
|
||||
st, _ := status.FromError(err)
|
||||
if st.Code().String() == "NotFound" {
|
||||
return nil, errors.New("player not initialized")
|
||||
}
|
||||
logx.Errorf("failed to get player by user id: %v", err)
|
||||
return nil, errors.New("get player failed")
|
||||
}
|
||||
|
||||
player := playerResp.GetPlayers()
|
||||
if player == nil {
|
||||
return nil, errors.New("player not initialized")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.PlayerRpc.AddPlayerServices(l.ctx, &playerservice.AddPlayerServicesReq{
|
||||
PlayerId: player.Id,
|
||||
GameId: req.GameId,
|
||||
Title: req.Title,
|
||||
Description: req.Description,
|
||||
@@ -41,7 +63,7 @@ func (l *CreateServiceLogic) CreateService(req *types.CreateServiceReq) (resp *t
|
||||
Availability: req.Availability,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("failed to create player service: " + err.Error())
|
||||
logx.Errorf("failed to create player service: %v", err)
|
||||
return nil, errors.New("failed to create player service")
|
||||
}
|
||||
return
|
||||
|
||||
@@ -5,6 +5,7 @@ package player
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"juwan-backend/app/player/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type UpdatePlayerStatusLogic struct {
|
||||
@@ -30,13 +32,27 @@ func NewUpdatePlayerStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *UpdatePlayerStatusLogic) UpdatePlayerStatus(req *types.UpdatePlayerStatusReq) (resp *types.EmptyResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
userId, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
playerResp, err := l.svcCtx.PlayerRpc.GetPlayerByUserId(l.ctx, &pb.SearchPlayersReq{UserId: &userId})
|
||||
if err != nil {
|
||||
st, _ := status.FromError(err)
|
||||
if st.Code().String() == "NotFound" {
|
||||
return nil, errors.New("player not initialized")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
player := playerResp.GetPlayers()
|
||||
if player == nil {
|
||||
return nil, errors.New("player not initialized")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.PlayerRpc.UpdatePlayers(l.ctx, &pb.UpdatePlayersReq{
|
||||
Id: userId,
|
||||
Id: player.Id,
|
||||
Status: &req.Status,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user