fix: api descript
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user