feat(shop-role): 实现店铺角色继承功能和权限检查优化
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m39s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m39s
- 新增店铺角色管理 API 和数据模型 - 实现角色继承和权限检查逻辑 - 添加流程测试框架和集成测试 - 更新权限服务和账号管理逻辑 - 添加数据库迁移脚本 - 归档 OpenSpec 变更文档 Ultraworked with Sisyphus
This commit is contained in:
75
internal/handler/admin/shop_role.go
Normal file
75
internal/handler/admin/shop_role.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
shopService "github.com/break/junhong_cmp_fiber/internal/service/shop"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type ShopRoleHandler struct {
|
||||
service *shopService.Service
|
||||
}
|
||||
|
||||
func NewShopRoleHandler(service *shopService.Service) *ShopRoleHandler {
|
||||
return &ShopRoleHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *ShopRoleHandler) AssignShopRoles(c *fiber.Ctx) error {
|
||||
shopIDStr := c.Params("shop_id")
|
||||
shopID, err := strconv.ParseUint(shopIDStr, 10, 32)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "店铺ID格式错误")
|
||||
}
|
||||
|
||||
var req dto.AssignShopRolesRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.AssignRolesToShop(c.UserContext(), uint(shopID), req.RoleIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
func (h *ShopRoleHandler) GetShopRoles(c *fiber.Ctx) error {
|
||||
shopIDStr := c.Params("shop_id")
|
||||
shopID, err := strconv.ParseUint(shopIDStr, 10, 32)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "店铺ID格式错误")
|
||||
}
|
||||
|
||||
result, err := h.service.GetShopRoles(c.UserContext(), uint(shopID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
func (h *ShopRoleHandler) DeleteShopRole(c *fiber.Ctx) error {
|
||||
shopIDStr := c.Params("shop_id")
|
||||
shopID, err := strconv.ParseUint(shopIDStr, 10, 32)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "店铺ID格式错误")
|
||||
}
|
||||
|
||||
roleIDStr := c.Params("role_id")
|
||||
roleID, err := strconv.ParseUint(roleIDStr, 10, 32)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "角色ID格式错误")
|
||||
}
|
||||
|
||||
if err := h.service.DeleteShopRole(c.UserContext(), uint(shopID), uint(roleID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user