feat: 新增系列授权 Handler 和路由(/shop-series-grants)
Handler 实现 POST /shop-series-grants(创建)、GET /shop-series-grants(列表)、GET /shop-series-grants/:id(详情)、PUT /shop-series-grants/:id(更新佣金和强充配置)、PUT /shop-series-grants/:id/packages(管理授权内套餐)、DELETE /shop-series-grants/:id(删除)六个接口。 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
131
internal/handler/admin/shop_series_grant.go
Normal file
131
internal/handler/admin/shop_series_grant.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
grantService "github.com/break/junhong_cmp_fiber/internal/service/shop_series_grant"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
// ShopSeriesGrantHandler 代理系列授权 Handler
|
||||
type ShopSeriesGrantHandler struct {
|
||||
service *grantService.Service
|
||||
}
|
||||
|
||||
// NewShopSeriesGrantHandler 创建代理系列授权 Handler
|
||||
func NewShopSeriesGrantHandler(service *grantService.Service) *ShopSeriesGrantHandler {
|
||||
return &ShopSeriesGrantHandler{service: service}
|
||||
}
|
||||
|
||||
// Create 创建系列授权
|
||||
// POST /api/admin/shop-series-grants
|
||||
func (h *ShopSeriesGrantHandler) Create(c *fiber.Ctx) error {
|
||||
var req dto.CreateShopSeriesGrantRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.Create(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// List 查询系列授权列表
|
||||
// GET /api/admin/shop-series-grants
|
||||
func (h *ShopSeriesGrantHandler) List(c *fiber.Ctx) error {
|
||||
var req dto.ShopSeriesGrantListRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.List(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, result.List, result.Total, result.Page, result.PageSize)
|
||||
}
|
||||
|
||||
// Get 查询系列授权详情
|
||||
// GET /api/admin/shop-series-grants/:id
|
||||
func (h *ShopSeriesGrantHandler) Get(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的授权ID")
|
||||
}
|
||||
|
||||
result, err := h.service.Get(c.UserContext(), uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// Update 更新系列授权
|
||||
// PUT /api/admin/shop-series-grants/:id
|
||||
func (h *ShopSeriesGrantHandler) Update(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的授权ID")
|
||||
}
|
||||
|
||||
var req dto.UpdateShopSeriesGrantRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.Update(c.UserContext(), uint(id), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// ManagePackages 管理授权套餐
|
||||
// PUT /api/admin/shop-series-grants/:id/packages
|
||||
func (h *ShopSeriesGrantHandler) ManagePackages(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的授权ID")
|
||||
}
|
||||
|
||||
var req dto.ManageGrantPackagesRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.ManagePackages(c.UserContext(), uint(id), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// Delete 删除系列授权
|
||||
// DELETE /api/admin/shop-series-grants/:id
|
||||
func (h *ShopSeriesGrantHandler) Delete(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseUint(idStr, 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)
|
||||
}
|
||||
Reference in New Issue
Block a user