少提交的东西
This commit is contained in:
@@ -3,22 +3,71 @@ package routes
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||||
)
|
||||
|
||||
// registerRoleRoutes 注册角色相关路由
|
||||
func registerRoleRoutes(api fiber.Router, h *handler.RoleHandler) {
|
||||
func registerRoleRoutes(api fiber.Router, h *admin.RoleHandler, doc *openapi.Generator, basePath string) {
|
||||
roles := api.Group("/roles")
|
||||
groupPath := basePath + "/roles"
|
||||
|
||||
// 角色 CRUD
|
||||
roles.Post("", h.Create) // POST /api/v1/roles
|
||||
roles.Get("", h.List) // GET /api/v1/roles
|
||||
roles.Get("/:id", h.Get) // GET /api/v1/roles/:id
|
||||
roles.Put("/:id", h.Update) // PUT /api/v1/roles/:id
|
||||
roles.Delete("/:id", h.Delete) // DELETE /api/v1/roles/:id
|
||||
Register(roles, doc, groupPath, "POST", "", h.Create, RouteSpec{
|
||||
Summary: "创建角色",
|
||||
Tags: []string{"Role"},
|
||||
Input: new(model.CreateRoleRequest),
|
||||
Output: new(model.RoleResponse),
|
||||
})
|
||||
|
||||
Register(roles, doc, groupPath, "GET", "", h.List, RouteSpec{
|
||||
Summary: "角色列表",
|
||||
Tags: []string{"Role"},
|
||||
Input: new(model.RoleListRequest),
|
||||
Output: new(model.RolePageResult),
|
||||
})
|
||||
|
||||
Register(roles, doc, groupPath, "GET", "/:id", h.Get, RouteSpec{
|
||||
Summary: "获取角色详情",
|
||||
Tags: []string{"Role"},
|
||||
Input: new(model.IDReq),
|
||||
Output: new(model.RoleResponse),
|
||||
})
|
||||
|
||||
Register(roles, doc, groupPath, "PUT", "/:id", h.Update, RouteSpec{
|
||||
Summary: "更新角色",
|
||||
Tags: []string{"Role"},
|
||||
Input: new(model.UpdateRoleParams),
|
||||
Output: new(model.RoleResponse),
|
||||
})
|
||||
|
||||
Register(roles, doc, groupPath, "DELETE", "/:id", h.Delete, RouteSpec{
|
||||
Summary: "删除角色",
|
||||
Tags: []string{"Role"},
|
||||
Input: new(model.IDReq),
|
||||
Output: nil,
|
||||
})
|
||||
|
||||
// 角色-权限关联
|
||||
roles.Post("/:id/permissions", h.AssignPermissions) // POST /api/v1/roles/:id/permissions
|
||||
roles.Get("/:id/permissions", h.GetPermissions) // GET /api/v1/roles/:id/permissions
|
||||
roles.Delete("/:role_id/permissions/:perm_id", h.RemovePermission) // DELETE /api/v1/roles/:role_id/permissions/:perm_id
|
||||
Register(roles, doc, groupPath, "POST", "/:id/permissions", h.AssignPermissions, RouteSpec{
|
||||
Summary: "分配权限",
|
||||
Tags: []string{"Role"},
|
||||
Input: new(model.AssignPermissionsParams),
|
||||
Output: nil,
|
||||
})
|
||||
|
||||
Register(roles, doc, groupPath, "GET", "/:id/permissions", h.GetPermissions, RouteSpec{
|
||||
Summary: "获取角色权限",
|
||||
Tags: []string{"Role"},
|
||||
Input: new(model.IDReq),
|
||||
Output: new([]model.Permission),
|
||||
})
|
||||
|
||||
Register(roles, doc, groupPath, "DELETE", "/:role_id/permissions/:perm_id", h.RemovePermission, RouteSpec{
|
||||
Summary: "移除权限",
|
||||
Tags: []string{"Role"},
|
||||
Input: new(model.RemovePermissionParams),
|
||||
Output: nil,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user