All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m9s
主要功能: - 添加企业卡授权/回收接口 (POST /enterprises/:id/allocate-cards, recall-cards) - 添加授权记录管理接口 (GET/PUT /authorizations) - 实现代理用户数据权限过滤(只能查看自己店铺下企业的授权记录) - 添加 GORM callback 支持授权记录表的数据权限过滤 技术改进: - 原生 SQL 查询手动添加数据权限过滤(ListWithJoin, GetByIDWithJoin) - 移除卡授权预检接口(allocate-cards/preview),保留内部方法 - 完善单元测试和集成测试覆盖
121 lines
3.3 KiB
Go
121 lines
3.3 KiB
Go
package admin
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
|
enterpriseCardService "github.com/break/junhong_cmp_fiber/internal/service/enterprise_card"
|
|
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
|
"github.com/break/junhong_cmp_fiber/pkg/response"
|
|
)
|
|
|
|
type EnterpriseCardHandler struct {
|
|
service *enterpriseCardService.Service
|
|
}
|
|
|
|
func NewEnterpriseCardHandler(service *enterpriseCardService.Service) *EnterpriseCardHandler {
|
|
return &EnterpriseCardHandler{service: service}
|
|
}
|
|
|
|
func (h *EnterpriseCardHandler) AllocateCards(c *fiber.Ctx) error {
|
|
idStr := c.Params("id")
|
|
enterpriseID, err := strconv.ParseUint(idStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的企业ID")
|
|
}
|
|
|
|
var req dto.AllocateCardsReq
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
result, err := h.service.AllocateCards(c.UserContext(), uint(enterpriseID), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, result)
|
|
}
|
|
|
|
func (h *EnterpriseCardHandler) RecallCards(c *fiber.Ctx) error {
|
|
idStr := c.Params("id")
|
|
enterpriseID, err := strconv.ParseUint(idStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的企业ID")
|
|
}
|
|
|
|
var req dto.RecallCardsReq
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
result, err := h.service.RecallCards(c.UserContext(), uint(enterpriseID), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, result)
|
|
}
|
|
|
|
func (h *EnterpriseCardHandler) ListCards(c *fiber.Ctx) error {
|
|
idStr := c.Params("id")
|
|
enterpriseID, err := strconv.ParseUint(idStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的企业ID")
|
|
}
|
|
|
|
var req dto.EnterpriseCardListReq
|
|
if err := c.QueryParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
result, err := h.service.ListCards(c.UserContext(), uint(enterpriseID), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.SuccessWithPagination(c, result.Items, result.Total, result.Page, result.Size)
|
|
}
|
|
|
|
func (h *EnterpriseCardHandler) SuspendCard(c *fiber.Ctx) error {
|
|
enterpriseIDStr := c.Params("id")
|
|
enterpriseID, err := strconv.ParseUint(enterpriseIDStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的企业ID")
|
|
}
|
|
|
|
cardIDStr := c.Params("card_id")
|
|
cardID, err := strconv.ParseUint(cardIDStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的卡ID")
|
|
}
|
|
|
|
if err := h.service.SuspendCard(c.UserContext(), uint(enterpriseID), uint(cardID)); err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, nil)
|
|
}
|
|
|
|
func (h *EnterpriseCardHandler) ResumeCard(c *fiber.Ctx) error {
|
|
enterpriseIDStr := c.Params("id")
|
|
enterpriseID, err := strconv.ParseUint(enterpriseIDStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的企业ID")
|
|
}
|
|
|
|
cardIDStr := c.Params("card_id")
|
|
cardID, err := strconv.ParseUint(cardIDStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的卡ID")
|
|
}
|
|
|
|
if err := h.service.ResumeCard(c.UserContext(), uint(enterpriseID), uint(cardID)); err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, nil)
|
|
}
|