fix: api descript

This commit is contained in:
wwweww
2026-02-28 05:33:16 +08:00
parent 5930fb0dde
commit d2f33b4b96
243 changed files with 37065 additions and 780 deletions
@@ -0,0 +1,48 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type AddShopInvitationsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopInvitationsLogic {
return &AddShopInvitationsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// -----------------------shopInvitations-----------------------
func (l *AddShopInvitationsLogic) AddShopInvitations(in *pb.AddShopInvitationsReq) (*pb.AddShopInvitationsResp, error) {
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("create player service id failed")
}
_, err = l.svcCtx.ShopModelRW.ShopInvitations.Create().
SetID(idResp.Id).
SetShopID(in.ShopId).
SetPlayerID(in.PlayerId).
SetStatus(in.Status).
SetInvitedBy(in.InvitedBy).
Save(l.ctx)
if err != nil {
return nil, errors.New("add shop invitation failed")
}
return &pb.AddShopInvitationsResp{}, nil
}
@@ -0,0 +1,48 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type AddShopPlayersLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopPlayersLogic {
return &AddShopPlayersLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// -----------------------shopPlayers-----------------------
func (l *AddShopPlayersLogic) AddShopPlayers(in *pb.AddShopPlayersReq) (*pb.AddShopPlayersResp, error) {
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("create player service id failed")
}
_, err = l.svcCtx.ShopModelRW.ShopPlayers.Create().
SetID(idResp.Id).
SetShopID(in.ShopId).
SetPlayerID(in.PlayerId).
SetIsPrimary(in.IsPrimary).
Save(l.ctx)
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("add player service failed")
}
return &pb.AddShopPlayersResp{}, nil
}
@@ -0,0 +1,68 @@
package logic
import (
"context"
"encoding/json"
"errors"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/shopspring/decimal"
"github.com/zeromicro/go-zero/core/logx"
)
type AddShopsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopsLogic {
return &AddShopsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// -----------------------shops-----------------------
func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("create player service id failed")
}
var templateConfig map[string]interface{}
err = json.Unmarshal([]byte(in.TemplateConfig), &templateConfig)
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("invalid template config")
}
_, err = l.svcCtx.ShopModelRO.Shops.Create().
SetID(idResp.Id).
SetOwnerID(in.OwnerId).
SetName(in.Name).
SetBanner(in.Banner).
SetDescription(in.Description).
SetRating(decimal.NewFromFloat(in.Rating)).
SetTotalOrders(int(in.TotalOrders)).
SetPlayerCount(int(in.PlayerCount)).
SetNillableCommissionType(&in.CommissionType).
SetCommissionValue(decimal.NewFromFloat(in.CommissionValue)).
SetAllowMultiShop(in.AllowMultiShop).
SetAllowIndependentOrders(in.AllowIndependentOrders).
SetDispatchMode(in.DispatchMode).
SetAnnouncements(in.Announcements).
SetTemplateConfig(templateConfig).
Save(l.ctx)
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("add player service failed")
}
return &pb.AddShopsResp{}, nil
}
@@ -0,0 +1,35 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type DelShopInvitationsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelShopInvitationsLogic {
return &DelShopInvitationsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelShopInvitationsLogic) DelShopInvitations(in *pb.DelShopInvitationsReq) (*pb.DelShopInvitationsResp, error) {
err := l.svcCtx.ShopModelRW.ShopInvitations.DeleteOneID(in.Id).Exec(l.ctx)
if err != nil {
logx.Errorf("delete shop invitations failed, %s", err.Error())
return nil, errors.New("delete failed")
}
return &pb.DelShopInvitationsResp{}, nil
}
@@ -0,0 +1,35 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type DelShopPlayersLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelShopPlayersLogic {
return &DelShopPlayersLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelShopPlayersLogic) DelShopPlayers(in *pb.DelShopPlayersReq) (*pb.DelShopPlayersResp, error) {
err := l.svcCtx.ShopModelRO.ShopPlayers.DeleteOneID(in.Id).Exec(l.ctx)
if err != nil {
logx.Errorf("delete shop players failed, %s", err.Error())
return nil, errors.New("delete failed")
}
return &pb.DelShopPlayersResp{}, nil
}
@@ -0,0 +1,35 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type DelShopsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelShopsLogic {
return &DelShopsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelShopsLogic) DelShops(in *pb.DelShopsReq) (*pb.DelShopsResp, error) {
err := l.svcCtx.ShopModelRO.Shops.DeleteOneID(in.Id).Exec(l.ctx)
if err != nil {
logx.Errorf("delete shop failed, %s", err.Error())
return nil, errors.New("delete failed")
}
return &pb.DelShopsResp{}, nil
}
@@ -0,0 +1,50 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
//"juwan-backend/app/game/rpc/internal/models/shopinvitations"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetShopInvitationsByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetShopInvitationsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopInvitationsByIdLogic {
return &GetShopInvitationsByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetShopInvitationsByIdLogic) GetShopInvitationsById(in *pb.GetShopInvitationsByIdReq) (*pb.GetShopInvitationsByIdResp, error) {
shopInvitation, err := l.svcCtx.ShopModelRO.ShopInvitations.Query().Where(shopinvitations.IDEQ(in.Id)).First(l.ctx)
if err != nil {
logx.WithContext(l.ctx).Errorf("GetShopInvitationsByIdLogic err: %v", err)
return nil, errors.New("get shop invitations by id failed")
}
pbShopInvitation := pb.ShopInvitations{
Id: shopInvitation.ID,
ShopId: shopInvitation.ShopID,
PlayerId: shopInvitation.PlayerID,
Status: shopInvitation.Status,
InvitedBy: shopInvitation.InvitedBy,
CreatedAt: shopInvitation.CreatedAt.Unix(),
}
if shopInvitation.RespondedAt != nil {
pbShopInvitation.RespondedAt = shopInvitation.RespondedAt.Unix()
}
return &pb.GetShopInvitationsByIdResp{ShopInvitations: &pbShopInvitation}, nil
}
@@ -0,0 +1,46 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetShopPlayersByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetShopPlayersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopPlayersByIdLogic {
return &GetShopPlayersByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetShopPlayersByIdLogic) GetShopPlayersById(in *pb.GetShopPlayersByIdReq) (*pb.GetShopPlayersByIdResp, error) {
shopPlayer, err := l.svcCtx.ShopModelRO.ShopPlayers.Query().Where(shopplayers.IDEQ(in.Id)).First(l.ctx)
if err != nil {
logx.WithContext(l.ctx).Errorf("GetShopPlayersByIdLogic err: %v", err)
return nil, errors.New("get shop players by id failed")
}
pbShopPlayer := pb.ShopPlayers{
ShopId: shopPlayer.ShopID,
PlayerId: shopPlayer.PlayerID,
IsPrimary: shopPlayer.IsPrimary,
JoinedAt: shopPlayer.JoinedAt.Unix(),
}
if shopPlayer.LeftAt != nil {
pbShopPlayer.LeftAt = shopPlayer.LeftAt.Unix()
}
return &pb.GetShopPlayersByIdResp{ShopPlayers: &pbShopPlayer}, nil
}
@@ -0,0 +1,67 @@
package logic
import (
"context"
"encoding/json"
"errors"
"juwan-backend/app/shop/rpc/internal/models/shops"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetShopsByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetShopsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopsByIdLogic {
return &GetShopsByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetShopsByIdLogic) GetShopsById(in *pb.GetShopsByIdReq) (*pb.GetShopsByIdResp, error) {
shop, err := l.svcCtx.ShopModelRO.Shops.Query().Where(shops.IDEQ(in.Id)).First(l.ctx)
if err != nil {
logx.WithContext(l.ctx).Errorf("GetShopsByIdLogic err: %v", err)
return nil, errors.New("get shops by id failed")
}
templateConfigBytes, err := json.Marshal(shop.TemplateConfig)
if err != nil {
logx.WithContext(l.ctx).Errorf("GetShopsByIdLogic marshal template config err: %v", err)
return nil, errors.New("get shops by id failed")
}
pbShop := pb.Shops{
Id: shop.ID,
OwnerId: shop.OwnerID,
Name: shop.Name,
Rating: shop.Rating.InexactFloat64(),
TotalOrders: int64(shop.TotalOrders),
PlayerCount: int64(shop.PlayerCount),
CommissionType: shop.CommissionType,
CommissionValue: shop.CommissionValue.InexactFloat64(),
AllowMultiShop: shop.AllowMultiShop,
AllowIndependentOrders: shop.AllowIndependentOrders,
DispatchMode: shop.DispatchMode,
Announcements: shop.Announcements,
TemplateConfig: string(templateConfigBytes),
CreatedAt: shop.CreatedAt.Unix(),
UpdatedAt: shop.UpdatedAt.Unix(),
}
if shop.Banner != nil {
pbShop.Banner = *shop.Banner
}
if shop.Description != nil {
pbShop.Description = *shop.Description
}
return &pb.GetShopsByIdResp{Shops: &pbShop}, nil
}
@@ -0,0 +1,28 @@
package logic
import (
"context"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchShopInvitationsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchShopInvitationsLogic {
return &SearchShopInvitationsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchShopInvitationsLogic) SearchShopInvitations(in *pb.SearchShopInvitationsReq) (*pb.SearchShopInvitationsResp, error) {
// TODO: implement search logic based on the provided criteria in the request
return &pb.SearchShopInvitationsResp{}, nil
}
@@ -0,0 +1,26 @@
package logic
import (
"context"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchShopPlayersLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchShopPlayersLogic {
return &SearchShopPlayersLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchShopPlayersLogic) SearchShopPlayers(in *pb.SearchShopPlayersReq) (*pb.SearchShopPlayersResp, error) {
}
@@ -0,0 +1,27 @@
package logic
import (
"context"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchShopsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchShopsLogic {
return &SearchShopsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchShopsLogic) SearchShops(in *pb.SearchShopsReq) (*pb.SearchShopsResp, error) {
}
@@ -0,0 +1,30 @@
package logic
import (
"context"
"errors"
"time"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateShopInvitationsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopInvitationsLogic {
return &UpdateShopInvitationsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateShopInvitationsLogic) UpdateShopInvitations(in *pb.UpdateShopInvitationsReq) (*pb.UpdateShopInvitationsResp, error) {
}
@@ -0,0 +1,32 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/models"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"time"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateShopPlayersLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopPlayersLogic {
return &UpdateShopPlayersLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateShopPlayersLogic) UpdateShopPlayers(in *pb.UpdateShopPlayersReq) (*pb.UpdateShopPlayersResp, error) {
}
@@ -0,0 +1,32 @@
package logic
import (
"context"
"encoding/json"
"errors"
"time"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/shopspring/decimal"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateShopsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopsLogic {
return &UpdateShopsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateShopsLogic) UpdateShops(in *pb.UpdateShopsReq) (*pb.UpdateShopsResp, error) {
}