fix: 店铺邀请改为查找打手身份
This commit is contained in:
@@ -10,5 +10,6 @@ import (
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
ShopRpcConf zrpc.RpcClientConf
|
||||
ShopRpcConf zrpc.RpcClientConf
|
||||
PlayerRpcConf zrpc.RpcClientConf
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package shop
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/player/rpc/playerservice"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
@@ -13,6 +14,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type AcceptInvitationLogic struct {
|
||||
@@ -35,6 +38,18 @@ func (l *AcceptInvitationLogic) AcceptInvitation(req *types.AcceptInvitationReq)
|
||||
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() == codes.NotFound {
|
||||
return nil, errors.New("bad request: invitation not found or not owned by user")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
player := playerResp.GetPlayers()
|
||||
if player == nil {
|
||||
return nil, errors.New("bad request: invitation not found or not owned by user")
|
||||
}
|
||||
invitation, err := l.svcCtx.ShopRpc.GetShopInvitationsById(l.ctx, &pb.GetShopInvitationsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -42,14 +57,14 @@ func (l *AcceptInvitationLogic) AcceptInvitation(req *types.AcceptInvitationReq)
|
||||
if invitation.ShopInvitations == nil {
|
||||
return nil, errors.New("invitation not found")
|
||||
}
|
||||
if invitation.ShopInvitations.PlayerId != userId {
|
||||
if invitation.ShopInvitations.PlayerId != player.Id {
|
||||
return nil, errors.New("bad request: invitation not found or not owned by user")
|
||||
}
|
||||
|
||||
i, err := l.svcCtx.ShopRpc.UpdateShopInvitations(l.ctx, &pb.UpdateShopInvitationsReq{
|
||||
Id: req.Id,
|
||||
ShopId: invitation.ShopInvitations.ShopId,
|
||||
PlayerId: userId,
|
||||
PlayerId: player.Id,
|
||||
Status: "accepted",
|
||||
InvitedBy: invitation.ShopInvitations.InvitedBy,
|
||||
CreatedAt: invitation.ShopInvitations.CreatedAt,
|
||||
@@ -60,7 +75,7 @@ func (l *AcceptInvitationLogic) AcceptInvitation(req *types.AcceptInvitationReq)
|
||||
}
|
||||
_, err = l.svcCtx.ShopRpc.AddShopPlayers(l.ctx, &pb.AddShopPlayersReq{
|
||||
ShopId: i.ShopInvitations.ShopId,
|
||||
PlayerId: userId,
|
||||
PlayerId: player.Id,
|
||||
IsPrimary: false,
|
||||
JoinedAt: time.Now().Unix(),
|
||||
LeftAt: 0,
|
||||
|
||||
@@ -8,12 +8,15 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/player/rpc/playerservice"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type RejectInvitationLogic struct {
|
||||
@@ -36,6 +39,18 @@ func (l *RejectInvitationLogic) RejectInvitation(req *types.AcceptInvitationReq)
|
||||
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() == codes.NotFound {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
player := playerResp.GetPlayers()
|
||||
if player == nil {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
|
||||
invitation, err := l.svcCtx.ShopRpc.GetShopInvitationsById(l.ctx, &pb.GetShopInvitationsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
@@ -44,7 +59,7 @@ func (l *RejectInvitationLogic) RejectInvitation(req *types.AcceptInvitationReq)
|
||||
if invitation.ShopInvitations == nil {
|
||||
return nil, errors.New("invitation not found")
|
||||
}
|
||||
if invitation.ShopInvitations.PlayerId != userID {
|
||||
if invitation.ShopInvitations.PlayerId != player.Id {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"juwan-backend/app/player/rpc/playerservice"
|
||||
"juwan-backend/app/shop/api/internal/config"
|
||||
"juwan-backend/app/shop/rpc/shopservice"
|
||||
"juwan-backend/common/middlewares"
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
ShopRpc shopservice.ShopService
|
||||
PlayerRpc playerservice.PlayerService
|
||||
HeaderExtractorMiddleware rest.Middleware
|
||||
}
|
||||
|
||||
@@ -22,6 +24,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
ShopRpc: shopservice.NewShopService(zrpc.MustNewClient(c.ShopRpcConf)),
|
||||
PlayerRpc: playerservice.NewPlayerService(zrpc.MustNewClient(c.PlayerRpcConf)),
|
||||
HeaderExtractorMiddleware: middlewares.NewHeaderExtractorMiddleware().Handle,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user