86 lines
2.1 KiB
Lua
86 lines
2.1 KiB
Lua
---
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
--- Created by admin.
|
|
--- DateTime: 2025/9/25 08:19
|
|
---
|
|
|
|
local _M = {}
|
|
|
|
local dao = require("service.system.user")
|
|
local resp = require("util.response")
|
|
|
|
--验证请求头是否正确
|
|
local function checkReqHeader()
|
|
local headers = ngx.req.get_headers()
|
|
if headers["content-type"] ~= "application/json" then
|
|
local result = resp:json(0x000001)
|
|
resp:send(result)
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
--获取所有用户信息
|
|
function _M.get_alluser()
|
|
local code,ret = dao.getAllUser()
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
--根据用户id获取用户信息
|
|
function _M.get_user(m)
|
|
local id = m.id
|
|
local code,ret = dao.getUser(id)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
--根据用户id获取用户信息
|
|
function _M.add_user()
|
|
--获取请求头并进行校验
|
|
if checkReqHeader() == false then
|
|
return
|
|
end
|
|
--读取请求体的数据
|
|
ngx.req.read_body()
|
|
--获取请求数据
|
|
local body_data = ngx.req.get_body_data()
|
|
--判断请求体数据是否为空
|
|
if body_data == nil then
|
|
local result = resp:json(0x000001)
|
|
resp:send(result)
|
|
return
|
|
end
|
|
--ngx.say(body_data)
|
|
local code, ret = dao.addUser(body_data)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
--根据用户id删除用户信息
|
|
function _M.delete_user(m)
|
|
local id = m.id
|
|
local code, ret = dao.delete_user(id)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
--根据用户id删除用户信息
|
|
function _M.update_user(m)
|
|
local id = m.id
|
|
--读取请求体的数据
|
|
ngx.req.read_body()
|
|
--获取请求数据
|
|
local body_data = ngx.req.get_body_data()
|
|
--判断请求体数据是否为空
|
|
if body_data == nil then
|
|
local result = resp:json(0x000001)
|
|
resp:send(result)
|
|
return
|
|
end
|
|
local code, ret = dao.update_user(id, body_data)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
return _M |