refactor: 删除旧套餐系列/套餐分配 Handler 和路由
/shop-series-allocations 和 /shop-package-allocations 接口已被 /shop-series-grants 完全替代,开发阶段干净删除,不保留兼容接口。 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,137 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
shopPackageAllocationService "github.com/break/junhong_cmp_fiber/internal/service/shop_package_allocation"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type ShopPackageAllocationHandler struct {
|
||||
service *shopPackageAllocationService.Service
|
||||
}
|
||||
|
||||
func NewShopPackageAllocationHandler(service *shopPackageAllocationService.Service) *ShopPackageAllocationHandler {
|
||||
return &ShopPackageAllocationHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) Create(c *fiber.Ctx) error {
|
||||
var req dto.CreateShopPackageAllocationRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Create(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) Get(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Get(c.UserContext(), uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
var req dto.UpdateShopPackageAllocationRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Update(c.UserContext(), uint(id), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
if err := h.service.Delete(c.UserContext(), uint(id)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) List(c *fiber.Ctx) error {
|
||||
var req dto.ShopPackageAllocationListRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocations, total, err := h.service.List(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, allocations, total, req.Page, req.PageSize)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) UpdateStatus(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
var req dto.UpdateStatusRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
if err := h.service.UpdateStatus(c.UserContext(), uint(id), req.Status); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
|
||||
// UpdateCostPrice 更新成本价
|
||||
func (h *ShopPackageAllocationHandler) UpdateCostPrice(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
type UpdateCostPriceRequest struct {
|
||||
NewCostPrice int64 `json:"new_cost_price" validate:"required,min=0"`
|
||||
ChangeReason string `json:"change_reason" validate:"omitempty,max=255"`
|
||||
}
|
||||
|
||||
var req UpdateCostPriceRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.UpdateCostPrice(c.UserContext(), uint(id), req.NewCostPrice, req.ChangeReason)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
shopSeriesAllocationService "github.com/break/junhong_cmp_fiber/internal/service/shop_series_allocation"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type ShopSeriesAllocationHandler struct {
|
||||
service *shopSeriesAllocationService.Service
|
||||
}
|
||||
|
||||
func NewShopSeriesAllocationHandler(service *shopSeriesAllocationService.Service) *ShopSeriesAllocationHandler {
|
||||
return &ShopSeriesAllocationHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) Create(c *fiber.Ctx) error {
|
||||
var req dto.CreateShopSeriesAllocationRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Create(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) Get(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的系列分配 ID")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Get(c.UserContext(), uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的系列分配 ID")
|
||||
}
|
||||
|
||||
var req dto.UpdateShopSeriesAllocationRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Update(c.UserContext(), uint(id), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的系列分配 ID")
|
||||
}
|
||||
|
||||
if err := h.service.Delete(c.UserContext(), uint(id)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) List(c *fiber.Ctx) error {
|
||||
var req dto.ShopSeriesAllocationListRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocations, total, err := h.service.List(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, allocations, total, req.Page, req.PageSize)
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
func registerShopPackageAllocationRoutes(router fiber.Router, handler *admin.ShopPackageAllocationHandler, doc *openapi.Generator, basePath string) {
|
||||
allocations := router.Group("/shop-package-allocations")
|
||||
groupPath := basePath + "/shop-package-allocations"
|
||||
|
||||
Register(allocations, doc, groupPath, "GET", "", handler.List, RouteSpec{
|
||||
Summary: "单套餐分配列表",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.ShopPackageAllocationListRequest),
|
||||
Output: new(dto.ShopPackageAllocationPageResult),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "POST", "", handler.Create, RouteSpec{
|
||||
Summary: "创建单套餐分配",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.CreateShopPackageAllocationRequest),
|
||||
Output: new(dto.ShopPackageAllocationResponse),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "GET", "/:id", handler.Get, RouteSpec{
|
||||
Summary: "获取单套餐分配详情",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: new(dto.ShopPackageAllocationResponse),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "PUT", "/:id", handler.Update, RouteSpec{
|
||||
Summary: "更新单套餐分配",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.UpdateShopPackageAllocationParams),
|
||||
Output: new(dto.ShopPackageAllocationResponse),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "DELETE", "/:id", handler.Delete, RouteSpec{
|
||||
Summary: "删除单套餐分配",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "PUT", "/:id/status", handler.UpdateStatus, RouteSpec{
|
||||
Summary: "更新单套餐分配状态",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.UpdateStatusParams),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "PUT", "/:id/cost-price", handler.UpdateCostPrice, RouteSpec{
|
||||
Summary: "更新单套餐分配成本价",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: new(dto.ShopPackageAllocationResponse),
|
||||
Auth: true,
|
||||
})
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
func registerShopSeriesAllocationRoutes(router fiber.Router, handler *admin.ShopSeriesAllocationHandler, doc *openapi.Generator, basePath string) {
|
||||
allocations := router.Group("/shop-series-allocations")
|
||||
groupPath := basePath + "/shop-series-allocations"
|
||||
|
||||
Register(allocations, doc, groupPath, "GET", "", handler.List, RouteSpec{
|
||||
Summary: "系列分配列表",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.ShopSeriesAllocationListRequest),
|
||||
Output: new(dto.ShopSeriesAllocationPageResult),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "POST", "", handler.Create, RouteSpec{
|
||||
Summary: "创建系列分配",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.CreateShopSeriesAllocationRequest),
|
||||
Output: new(dto.ShopSeriesAllocationResponse),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "GET", "/:id", handler.Get, RouteSpec{
|
||||
Summary: "获取系列分配详情",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: new(dto.ShopSeriesAllocationResponse),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "PUT", "/:id", handler.Update, RouteSpec{
|
||||
Summary: "更新系列分配",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.UpdateShopSeriesAllocationParams),
|
||||
Output: new(dto.ShopSeriesAllocationResponse),
|
||||
Auth: true,
|
||||
})
|
||||
|
||||
Register(allocations, doc, groupPath, "DELETE", "/:id", handler.Delete, RouteSpec{
|
||||
Summary: "删除系列分配",
|
||||
Tags: []string{"套餐分配"},
|
||||
Input: new(dto.IDReq),
|
||||
Output: nil,
|
||||
Auth: true,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user