修复(#84): 补齐促销管理API实现文件
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package promo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
promoModel "github.com/perfect-panel/server/internal/model/promo"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
)
|
||||
|
||||
type GetPromoRuleListLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Get promo rule list
|
||||
func NewGetPromoRuleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPromoRuleListLogic {
|
||||
return &GetPromoRuleListLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPromoRuleListLogic) GetPromoRuleList(req *types.GetPromoRuleListRequest) (*types.GetPromoRuleListResponse, error) {
|
||||
total, list, err := l.svcCtx.PromoModel.QueryRuleList(l.ctx, promoModel.RuleFilter{
|
||||
Page: int(req.Page),
|
||||
Size: int(req.Size),
|
||||
Type: req.Type,
|
||||
Enabled: req.Enabled,
|
||||
Search: req.Search,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[GetPromoRuleList] Database Error", logger.Field("error", err.Error()))
|
||||
return nil, wrapQueryError("get promo rule list failed", err)
|
||||
}
|
||||
resp := &types.GetPromoRuleListResponse{
|
||||
Total: total,
|
||||
List: make([]types.PromoRule, 0, len(list)),
|
||||
}
|
||||
for _, item := range list {
|
||||
resp.List = append(resp.List, toRuleResponse(item))
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user