Refactor: Remove deprecated gRPC service files and implement new API structure
- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`. - Added new API server implementations for objectstory, player, and shop services. - Introduced configuration files for new APIs in `etc/*.yaml`. - Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`. - Removed unused user update handler and user API files. - Added utility functions for context management and HTTP header parsing. - Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
This commit is contained in:
@@ -5,9 +5,12 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"errors"
|
||||
"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"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -28,7 +31,44 @@ func NewAcceptInvitationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
||||
}
|
||||
|
||||
func (l *AcceptInvitationLogic) AcceptInvitation(req *types.AcceptInvitationReq) (resp *types.EmptyResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
AcceptInvitationLogic{}
|
||||
return
|
||||
userId, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
invitation, err := l.svcCtx.ShopRpc.GetShopInvitationsById(l.ctx, &pb.GetShopInvitationsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if invitation.ShopInvitations == nil {
|
||||
return nil, errors.New("invitation not found")
|
||||
}
|
||||
if invitation.ShopInvitations.PlayerId != userId {
|
||||
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,
|
||||
Status: "accepted",
|
||||
InvitedBy: invitation.ShopInvitations.InvitedBy,
|
||||
CreatedAt: invitation.ShopInvitations.CreatedAt,
|
||||
RespondedAt: time.Now().Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = l.svcCtx.ShopRpc.AddShopPlayers(l.ctx, &pb.AddShopPlayersReq{
|
||||
ShopId: i.ShopInvitations.ShopId,
|
||||
PlayerId: userId,
|
||||
IsPrimary: false,
|
||||
JoinedAt: time.Now().Unix(),
|
||||
LeftAt: 0,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = i
|
||||
return &types.EmptyResp{}, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
@@ -28,7 +31,41 @@ func NewAddAnnouncementLogic(ctx context.Context, svcCtx *svc.ServiceContext) *A
|
||||
}
|
||||
|
||||
func (l *AddAnnouncementLogic) AddAnnouncement(req *types.AnnouncementReq) (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
|
||||
}
|
||||
shop, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shop.Shops == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
if shop.Shops.OwnerId != userId {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
shop.Shops.Announcements = append(shop.Shops.Announcements, req.Content)
|
||||
_, err = l.svcCtx.ShopRpc.UpdateShops(l.ctx, &pb.UpdateShopsReq{
|
||||
Id: shop.Shops.Id,
|
||||
OwnerId: shop.Shops.OwnerId,
|
||||
Name: shop.Shops.Name,
|
||||
Banner: shop.Shops.Banner,
|
||||
Description: shop.Shops.Description,
|
||||
Rating: shop.Shops.Rating,
|
||||
TotalOrders: shop.Shops.TotalOrders,
|
||||
PlayerCount: shop.Shops.PlayerCount,
|
||||
CommissionType: shop.Shops.CommissionType,
|
||||
CommissionValue: shop.Shops.CommissionValue,
|
||||
AllowMultiShop: shop.Shops.AllowMultiShop,
|
||||
AllowIndependentOrders: shop.Shops.AllowIndependentOrders,
|
||||
DispatchMode: shop.Shops.DispatchMode,
|
||||
Announcements: shop.Shops.Announcements,
|
||||
TemplateConfig: shop.Shops.TemplateConfig,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
return &types.EmptyResp{}, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
@@ -28,7 +32,42 @@ func NewCreateShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
|
||||
}
|
||||
|
||||
func (l *CreateShopLogic) CreateShop(req *types.CreateShopReq) (resp *types.ShopProfile, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
ownerID, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if req.Name == "" {
|
||||
return nil, errors.New("name is required")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.ShopRpc.AddShops(l.ctx, &pb.AddShopsReq{
|
||||
OwnerId: ownerID,
|
||||
Name: req.Name,
|
||||
Description: req.Description,
|
||||
Rating: "5",
|
||||
TotalOrders: 0,
|
||||
PlayerCount: 0,
|
||||
CommissionType: req.CommissionType,
|
||||
CommissionValue: req.CommissionValue,
|
||||
AllowMultiShop: false,
|
||||
AllowIndependentOrders: true,
|
||||
DispatchMode: "manual",
|
||||
Announcements: []string{},
|
||||
TemplateConfig: `{}`,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
shop, err := getShopByOwnerID(l.ctx, l.svcCtx.ShopRpc, ownerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shop == nil {
|
||||
return nil, errors.New("create shop failed")
|
||||
}
|
||||
|
||||
return toShopProfile(shop), nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"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"
|
||||
)
|
||||
@@ -28,7 +31,48 @@ func NewDeleteAnnouncementLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *DeleteAnnouncementLogic) DeleteAnnouncement(req *types.DeleteAnnouncementReq) (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
|
||||
}
|
||||
|
||||
return
|
||||
shop, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shop.Shops == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
if shop.Shops.OwnerId != userID {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
|
||||
index := int(req.Index)
|
||||
if index < 0 || index >= len(shop.Shops.Announcements) {
|
||||
return nil, errors.New("announcement index out of range")
|
||||
}
|
||||
|
||||
shop.Shops.Announcements = append(shop.Shops.Announcements[:index], shop.Shops.Announcements[index+1:]...)
|
||||
_, err = l.svcCtx.ShopRpc.UpdateShops(l.ctx, &pb.UpdateShopsReq{
|
||||
Id: shop.Shops.Id,
|
||||
OwnerId: shop.Shops.OwnerId,
|
||||
Name: shop.Shops.Name,
|
||||
Banner: shop.Shops.Banner,
|
||||
Description: shop.Shops.Description,
|
||||
Rating: shop.Shops.Rating,
|
||||
TotalOrders: shop.Shops.TotalOrders,
|
||||
PlayerCount: shop.Shops.PlayerCount,
|
||||
CommissionType: shop.Shops.CommissionType,
|
||||
CommissionValue: shop.Shops.CommissionValue,
|
||||
AllowMultiShop: shop.Shops.AllowMultiShop,
|
||||
AllowIndependentOrders: shop.Shops.AllowIndependentOrders,
|
||||
DispatchMode: shop.Shops.DispatchMode,
|
||||
Announcements: shop.Shops.Announcements,
|
||||
TemplateConfig: shop.Shops.TemplateConfig,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.EmptyResp{}, nil
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -28,7 +30,19 @@ func NewGetMyShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMySh
|
||||
}
|
||||
|
||||
func (l *GetMyShopLogic) GetMyShop(req *types.EmptyResp) (resp *types.ShopProfile, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
userID, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
shop, err := getShopByOwnerID(l.ctx, l.svcCtx.ShopRpc, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shop == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
|
||||
return toShopProfile(shop), nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"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"
|
||||
)
|
||||
@@ -28,7 +31,28 @@ func NewGetShopIncomeStatsLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *GetShopIncomeStatsLogic) GetShopIncomeStats(req *types.AcceptInvitationReq) (resp *types.IncomeStatsResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
userID, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
shop, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shop.Shops == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
if shop.Shops.OwnerId != userID {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
|
||||
return &types.IncomeStatsResp{
|
||||
MonthlyIncome: "0",
|
||||
PendingSettlement: "0",
|
||||
TotalWithdrawn: "0",
|
||||
TotalOrders: shop.Shops.TotalOrders,
|
||||
CompletedOrders: shop.Shops.TotalOrders,
|
||||
}, nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
@@ -28,7 +31,13 @@ func NewGetShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopLo
|
||||
}
|
||||
|
||||
func (l *GetShopLogic) GetShop(req *types.ShopIdReq) (resp *types.ShopProfile, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
result, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if result.Shops == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
return toShopProfile(result.Shops), nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
@@ -28,7 +29,13 @@ func NewGetUserShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUs
|
||||
}
|
||||
|
||||
func (l *GetUserShopLogic) GetUserShop(req *types.UserIdReq) (resp *types.ShopProfile, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
shop, err := getShopByOwnerID(l.ctx, l.svcCtx.ShopRpc, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shop == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
return toShopProfile(shop), nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
"juwan-backend/app/shop/rpc/shopservice"
|
||||
)
|
||||
|
||||
func toShopProfile(in *pb.Shops) *types.ShopProfile {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var template any
|
||||
if in.TemplateConfig != "" {
|
||||
_ = json.Unmarshal([]byte(in.TemplateConfig), &template)
|
||||
}
|
||||
if template == nil {
|
||||
template = map[string]any{}
|
||||
}
|
||||
|
||||
ownerID := strconv.FormatInt(in.OwnerId, 10)
|
||||
return &types.ShopProfile{
|
||||
Id: strconv.FormatInt(in.Id, 10),
|
||||
Owner: types.UserProfile{
|
||||
Id: ownerID,
|
||||
Username: "",
|
||||
Nickname: "",
|
||||
Avatar: "",
|
||||
Role: "owner",
|
||||
VerifiedRoles: []string{"owner"},
|
||||
VerificationStatus: map[string]string{},
|
||||
CreatedAt: "",
|
||||
},
|
||||
Name: in.Name,
|
||||
Banner: in.Banner,
|
||||
Description: in.Description,
|
||||
Rating: in.Rating,
|
||||
TotalOrders: in.TotalOrders,
|
||||
PlayerCount: in.PlayerCount,
|
||||
CommissionType: in.CommissionType,
|
||||
CommissionValue: in.CommissionValue,
|
||||
Announcements: in.Announcements,
|
||||
TemplateConfig: template,
|
||||
}
|
||||
}
|
||||
|
||||
func getShopByOwnerID(ctx context.Context, rpc shopservice.ShopService, ownerID int64) (*pb.Shops, error) {
|
||||
list, err := rpc.SearchShops(ctx, &pb.SearchShopsReq{
|
||||
Page: 0,
|
||||
Limit: 1,
|
||||
OwnerId: ownerID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(list.Shops) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return list.Shops[0], nil
|
||||
}
|
||||
@@ -5,9 +5,13 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
@@ -28,7 +32,33 @@ func NewInvitePlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Invi
|
||||
}
|
||||
|
||||
func (l *InvitePlayerLogic) InvitePlayer(req *types.InvitationReq) (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
|
||||
}
|
||||
|
||||
return
|
||||
shop, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shop.Shops == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
if shop.Shops.OwnerId != userID {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.ShopRpc.AddShopInvitations(l.ctx, &pb.AddShopInvitationsReq{
|
||||
ShopId: req.Id,
|
||||
PlayerId: req.PlayerId,
|
||||
Status: "pending",
|
||||
InvitedBy: userID,
|
||||
CreatedAt: time.Now().Unix(),
|
||||
RespondedAt: 0,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.EmptyResp{}, nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package shop
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
@@ -28,7 +30,33 @@ func NewListShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListSho
|
||||
}
|
||||
|
||||
func (l *ListShopsLogic) ListShops(req *types.PageReq) (resp *types.ShopListResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
if req.Limit <= 0 {
|
||||
req.Limit = 20
|
||||
}
|
||||
|
||||
result, err := l.svcCtx.ShopRpc.SearchShops(l.ctx, &pb.SearchShopsReq{
|
||||
Page: req.Offset / req.Limit,
|
||||
Limit: req.Limit,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]types.ShopProfile, 0, len(result.Shops))
|
||||
for _, item := range result.Shops {
|
||||
profile := toShopProfile(item)
|
||||
if profile != nil {
|
||||
items = append(items, *profile)
|
||||
}
|
||||
}
|
||||
|
||||
return &types.ShopListResp{
|
||||
Items: items,
|
||||
Meta: types.PageMeta{
|
||||
Total: int64(len(items)),
|
||||
Offset: req.Offset,
|
||||
Limit: req.Limit,
|
||||
},
|
||||
}, nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,9 +5,13 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
@@ -28,7 +32,34 @@ func NewRejectInvitationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
||||
}
|
||||
|
||||
func (l *RejectInvitationLogic) RejectInvitation(req *types.AcceptInvitationReq) (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
|
||||
}
|
||||
|
||||
return
|
||||
invitation, err := l.svcCtx.ShopRpc.GetShopInvitationsById(l.ctx, &pb.GetShopInvitationsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if invitation.ShopInvitations == nil {
|
||||
return nil, errors.New("invitation not found")
|
||||
}
|
||||
if invitation.ShopInvitations.PlayerId != userID {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.ShopRpc.UpdateShopInvitations(l.ctx, &pb.UpdateShopInvitationsReq{
|
||||
Id: req.Id,
|
||||
ShopId: invitation.ShopInvitations.ShopId,
|
||||
PlayerId: invitation.ShopInvitations.PlayerId,
|
||||
Status: "rejected",
|
||||
InvitedBy: invitation.ShopInvitations.InvitedBy,
|
||||
CreatedAt: invitation.ShopInvitations.CreatedAt,
|
||||
RespondedAt: time.Now().Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.EmptyResp{}, nil
|
||||
}
|
||||
|
||||
@@ -5,9 +5,13 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
@@ -28,7 +32,31 @@ func NewRemovePlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Remo
|
||||
}
|
||||
|
||||
func (l *RemovePlayerLogic) RemovePlayer(req *types.InvitationReq) (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
|
||||
}
|
||||
|
||||
return
|
||||
shop, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shop.Shops == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
if shop.Shops.OwnerId != userID {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.ShopRpc.UpdateShopPlayers(l.ctx, &pb.UpdateShopPlayersReq{
|
||||
ShopId: req.Id,
|
||||
PlayerId: req.PlayerId,
|
||||
IsPrimary: false,
|
||||
LeftAt: time.Now().Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.EmptyResp{}, nil
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"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"
|
||||
)
|
||||
@@ -27,8 +30,69 @@ func NewUpdateShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateShopLogic) UpdateShop(req *types.ShopIdReq) (resp *types.ShopProfile, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
func (l *UpdateShopLogic) UpdateShop(req *types.UpdateShopReq) (resp *types.ShopProfile, err error) {
|
||||
userID, err := contextj.UserIDFrom(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
current, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if current.Shops == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
if current.Shops.OwnerId != userID {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
|
||||
name := current.Shops.Name
|
||||
if req.Name != "" {
|
||||
name = req.Name
|
||||
}
|
||||
description := current.Shops.Description
|
||||
if req.Description != "" {
|
||||
description = req.Description
|
||||
}
|
||||
commissionType := current.Shops.CommissionType
|
||||
if req.CommissionType != "" {
|
||||
commissionType = req.CommissionType
|
||||
}
|
||||
commissionValue := current.Shops.CommissionValue
|
||||
if req.CommissionValue != "" {
|
||||
commissionValue = req.CommissionValue
|
||||
}
|
||||
dispatchMode := current.Shops.DispatchMode
|
||||
if req.DispatchMode != "" {
|
||||
dispatchMode = req.DispatchMode
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.ShopRpc.UpdateShops(l.ctx, &pb.UpdateShopsReq{
|
||||
Id: current.Shops.Id,
|
||||
OwnerId: current.Shops.OwnerId,
|
||||
Name: name,
|
||||
Banner: current.Shops.Banner,
|
||||
Description: description,
|
||||
Rating: current.Shops.Rating,
|
||||
TotalOrders: current.Shops.TotalOrders,
|
||||
PlayerCount: current.Shops.PlayerCount,
|
||||
CommissionType: commissionType,
|
||||
CommissionValue: commissionValue,
|
||||
AllowMultiShop: req.AllowMultiShop,
|
||||
AllowIndependentOrders: req.AllowIndependentOrders,
|
||||
DispatchMode: dispatchMode,
|
||||
Announcements: current.Shops.Announcements,
|
||||
TemplateConfig: current.Shops.TemplateConfig,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
updated, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return toShopProfile(updated.Shops), nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,9 +5,13 @@ package shop
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"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"
|
||||
)
|
||||
@@ -28,7 +32,48 @@ func NewUpdateShopTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *UpdateShopTemplateLogic) UpdateShopTemplate(req *types.UpdateTemplateReq) (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
|
||||
}
|
||||
|
||||
shop, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shop.Shops == nil {
|
||||
return nil, errors.New("shop not found")
|
||||
}
|
||||
if shop.Shops.OwnerId != userID {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
|
||||
templateBytes, err := json.Marshal(map[string]any{"sections": req.Sections})
|
||||
if err != nil {
|
||||
return nil, errors.New("invalid sections")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.ShopRpc.UpdateShops(l.ctx, &pb.UpdateShopsReq{
|
||||
Id: shop.Shops.Id,
|
||||
OwnerId: shop.Shops.OwnerId,
|
||||
Name: shop.Shops.Name,
|
||||
Banner: shop.Shops.Banner,
|
||||
Description: shop.Shops.Description,
|
||||
Rating: shop.Shops.Rating,
|
||||
TotalOrders: shop.Shops.TotalOrders,
|
||||
PlayerCount: shop.Shops.PlayerCount,
|
||||
CommissionType: shop.Shops.CommissionType,
|
||||
CommissionValue: shop.Shops.CommissionValue,
|
||||
AllowMultiShop: shop.Shops.AllowMultiShop,
|
||||
AllowIndependentOrders: shop.Shops.AllowIndependentOrders,
|
||||
DispatchMode: shop.Shops.DispatchMode,
|
||||
Announcements: shop.Shops.Announcements,
|
||||
TemplateConfig: string(templateBytes),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.EmptyResp{}, nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user