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