AuthPlatform/src/api/system/department.lua

82 lines
2.2 KiB
Lua
Raw Normal View History

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/10/28 10:05
---
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local systemDepartment = require("service.system.department")
--定义相关路由前端接口url地址
local routes = {
--组织(部门)相关路由接口
{
paths = { "/yum/v1/system/departments" },
methods = { "GET" },
filter_fun = function(vars)
ngx.ctx.perms = "system::departments::list"
return true
end,
handler = systemDepartment.getSystemDepartments,
},
{
paths = { "/yum/v1/system/departments/:id" },
methods = { "GET" },
filter_fun = function(vars)
ngx.ctx.perms = "system::departments::view"
return true
end,
handler = systemDepartment.getSystemDepartment,
},
{
paths = { "/yum/v1/system/departments" },
methods = { "POST" },
filter_fun = function(vars)
ngx.ctx.perms = "system::departments::add"
return true
end,
handler = systemDepartment.addSystemDepartment,
},
{
paths = { "/yum/v1/system/departments/:id" },
methods = { "DELETE" },
filter_fun = function(vars)
ngx.ctx.perms = "system::departments::delete"
return true
end,
handler = systemDepartment.deleteSystemDepartment,
},
{
paths = { "/yum/v1/system/departments/:id" },
methods = { "PUT" },
filter_fun = function(vars)
ngx.ctx.perms = "system::departments::edit"
return true
end,
handler = systemDepartment.updateSystemDepartment,
},
}
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end