修复: GET /v1/admin/promo/price/list 字段不匹配导致 400
Build docker and publish / build (20.15.1) (push) Failing after 21m12s
Build docker and publish / build (20.15.1) (pull_request) Failing after 22m17s

前端发 rule_id/subscribe_id (均可选), 后端 API 定义为 promo_rule_id
(required), 直接返回 "PromoRuleId is a required field"。

对齐前端约定 (与 usage/list 命名一致):
- API: promo_rule_id(required) → rule_id + subscribe_id, 均可选
- model.QueryPriceList: 改为接 PriceFilter, 按条件过滤
- 同步 fake mock 与校验测试签名
This commit is contained in:
2026-05-29 01:04:37 -07:00
parent b162022d39
commit e17dc4a273
7 changed files with 37 additions and 16 deletions
+2 -1
View File
@@ -52,9 +52,10 @@ type (
Items []PromoPriceItem `json:"items" validate:"required,min=1,dive"`
}
GetPromoPriceListRequest {
PromoRuleId int64 `form:"promo_rule_id" validate:"required,gt=0"`
Page int64 `form:"page" validate:"required,gt=0"`
Size int64 `form:"size" validate:"required,gt=0,lte=200"`
RuleId int64 `form:"rule_id,omitempty"`
SubscribeId int64 `form:"subscribe_id,omitempty"`
}
GetPromoPriceListResponse {
Total int64 `json:"total"`
@@ -54,7 +54,7 @@ func (fakePromoModel) DeletePrice(context.Context, int64) error {
return nil
}
func (fakePromoModel) QueryPriceList(context.Context, int64, int, int) (int64, []*promomodel.SubscribePromo, error) {
func (fakePromoModel) QueryPriceList(context.Context, promomodel.PriceFilter) (int64, []*promomodel.SubscribePromo, error) {
return 0, nil, nil
}
@@ -3,6 +3,7 @@ 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"
@@ -25,7 +26,12 @@ func NewGetPriceListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetP
}
func (l *GetPriceListLogic) GetPriceList(req *types.GetPromoPriceListRequest) (*types.GetPromoPriceListResponse, error) {
total, list, err := l.svcCtx.PromoModel.QueryPriceList(l.ctx, req.PromoRuleId, int(req.Page), int(req.Size))
total, list, err := l.svcCtx.PromoModel.QueryPriceList(l.ctx, promomodel.PriceFilter{
Page: int(req.Page),
Size: int(req.Size),
RuleId: req.RuleId,
SubscribeId: req.SubscribeId,
})
if err != nil {
l.Errorw("[GetPromoPriceList] Database Error", logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get promo price list error: %v", err.Error())
@@ -63,7 +63,7 @@ func (m *fakePromoModel) DeletePrice(context.Context, int64) error {
return nil
}
func (m *fakePromoModel) QueryPriceList(context.Context, int64, int, int) (int64, []*promo.SubscribePromo, error) {
func (m *fakePromoModel) QueryPriceList(context.Context, promo.PriceFilter) (int64, []*promo.SubscribePromo, error) {
return 0, nil, nil
}
+21 -8
View File
@@ -24,7 +24,7 @@ type Model interface {
UpsertPrices(ctx context.Context, ruleId int64, items []*SubscribePromo) error
FindPrice(ctx context.Context, id int64) (*SubscribePromo, error)
DeletePrice(ctx context.Context, id int64) error
QueryPriceList(ctx context.Context, ruleId int64, page, size int) (int64, []*SubscribePromo, error)
QueryPriceList(ctx context.Context, params PriceFilter) (int64, []*SubscribePromo, error)
QueryUsageList(ctx context.Context, params UsageFilter) (int64, []*Usage, error)
Transaction(ctx context.Context, fn func(db *gorm.DB) error) error
}
@@ -38,6 +38,13 @@ type UsageFilter struct {
OrderNo string
}
type PriceFilter struct {
Page int
Size int
RuleId int64
SubscribeId int64
}
type defaultPromoModel struct {
db *gorm.DB
}
@@ -164,20 +171,26 @@ func (m *defaultPromoModel) DeletePrice(ctx context.Context, id int64) error {
return m.db.WithContext(ctx).Delete(&SubscribePromo{}, id).Error
}
func (m *defaultPromoModel) QueryPriceList(ctx context.Context, ruleId int64, page, size int) (int64, []*SubscribePromo, error) {
if page <= 0 {
page = 1
func (m *defaultPromoModel) QueryPriceList(ctx context.Context, params PriceFilter) (int64, []*SubscribePromo, error) {
if params.Page <= 0 {
params.Page = 1
}
if size <= 0 {
size = 10
if params.Size <= 0 {
params.Size = 10
}
var total int64
var list []*SubscribePromo
db := m.db.WithContext(ctx).Model(&SubscribePromo{}).Where("promo_rule_id = ?", ruleId)
db := m.db.WithContext(ctx).Model(&SubscribePromo{})
if params.RuleId > 0 {
db = db.Where("promo_rule_id = ?", params.RuleId)
}
if params.SubscribeId > 0 {
db = db.Where("subscribe_id = ?", params.SubscribeId)
}
if err := db.Count(&total).Error; err != nil {
return 0, nil, err
}
err := db.Order("id DESC").Limit(size).Offset((page - 1) * size).Find(&list).Error
err := db.Order("id DESC").Limit(params.Size).Offset((params.Page - 1) * params.Size).Find(&list).Error
return total, list, err
}
+1 -1
View File
@@ -34,7 +34,7 @@ func TestPromoListPageSizeLimit(t *testing.T) {
{
name: "price list",
req: GetPromoPriceListRequest{
PromoRuleId: 1,
RuleId: 1,
Page: 1,
Size: 201,
},
+2 -1
View File
@@ -1436,9 +1436,10 @@ type GetPreSendEmailCountResponse struct {
}
type GetPromoPriceListRequest struct {
PromoRuleId int64 `form:"promo_rule_id" validate:"required,gt=0"`
Page int64 `form:"page" validate:"required,gt=0"`
Size int64 `form:"size" validate:"required,gt=0,lte=200"`
RuleId int64 `form:"rule_id,omitempty"`
SubscribeId int64 `form:"subscribe_id,omitempty"`
}
type GetPromoPriceListResponse struct {