添加管理员sql和api
This commit is contained in:
119
server/api/admin.api
Normal file
119
server/api/admin.api
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
// 公共响应结构体(基础字段:状态码、提示信息)
|
||||||
|
type BaseResp {
|
||||||
|
Code int32 `json:"code"` // 0成功,非0失败
|
||||||
|
Message string `json:"message"` // 提示信息
|
||||||
|
}
|
||||||
|
|
||||||
|
// 管理员信息结构体(与表字段对应)
|
||||||
|
type AdminInfo {
|
||||||
|
Id int64 `json:"id"` // 用户ID
|
||||||
|
Username string `json:"username"` // 用户名
|
||||||
|
Password string `json:"password"` // 密码(仅创建/更新时传递)
|
||||||
|
CoverUrl string `json:"cover_url"` // 封面URL
|
||||||
|
Intro string `json:"intro"` // 简介
|
||||||
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
|
Role string `json:"role"` // 角色(super_admin/normal_admin)
|
||||||
|
Status int32 `json:"status"` // 1启用,0禁用
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 管理员列表相关
|
||||||
|
type ListAdminReq {
|
||||||
|
Page int32 `json:"page,optional" form:"page"` // 页码,默认1
|
||||||
|
Size int32 `json:"size,optional" form:"size"` // 每页条数,默认10
|
||||||
|
Role string `json:"role,optional" form:"role"` // 按角色筛选
|
||||||
|
Status int32 `json:"status,optional" form:"status"` // 按状态筛选
|
||||||
|
}
|
||||||
|
|
||||||
|
// 列表响应数据体
|
||||||
|
type ListAdminData {
|
||||||
|
Total int64 `json:"total"` // 总条数
|
||||||
|
List []AdminInfo `json:"list"` // 管理员列表
|
||||||
|
}
|
||||||
|
|
||||||
|
// 列表完整响应(显式嵌套BaseResp)
|
||||||
|
type ListAdminResp {
|
||||||
|
BaseResp // 继承基础响应字段
|
||||||
|
Data ListAdminData `json:"data"` // 业务数据
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 创建管理员相关
|
||||||
|
type CreateAdminReq {
|
||||||
|
Username string `json:"username" form:"username"` // 用户名(必填)
|
||||||
|
Password string `json:"password" form:"password"` // 密码(必填,需加密)
|
||||||
|
CoverUrl string `json:"cover_url,optional" form:"cover_url"` // 封面URL(可选)
|
||||||
|
Intro string `json:"intro,optional" form:"intro"` // 简介(可选)
|
||||||
|
Role string `json:"role,optional" form:"role"` // 角色(默认normal_admin)
|
||||||
|
Status int32 `json:"status,optional" form:"status"` // 状态(默认1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建响应数据体
|
||||||
|
type CreateAdminData {
|
||||||
|
Id int64 `json:"id"` // 新增的管理员ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建完整响应(显式嵌套BaseResp)
|
||||||
|
type CreateAdminResp {
|
||||||
|
BaseResp // 继承基础响应字段
|
||||||
|
Data CreateAdminData `json:"data,optional"` // 业务数据(可选)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 更新管理员相关
|
||||||
|
type UpdateAdminReq {
|
||||||
|
Id int64 `json:"id" form:"id"` // 用户ID(必填)
|
||||||
|
Username string `json:"username,optional" form:"username"` // 用户名(可选)
|
||||||
|
Password string `json:"password,optional" form:"password"` // 密码(可选)
|
||||||
|
CoverUrl string `json:"cover_url,optional" form:"cover_url"` // 封面URL(可选)
|
||||||
|
Intro string `json:"intro,optional" form:"intro"` // 简介(可选)
|
||||||
|
Role string `json:"role,optional" form:"role"` // 角色(可选)
|
||||||
|
Status int32 `json:"status,optional" form:"status"` // 状态(可选)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新完整响应(显式嵌套BaseResp,无额外数据)
|
||||||
|
type UpdateAdminResp {
|
||||||
|
BaseResp // 仅继承基础响应字段
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 获取单个管理员详情相关
|
||||||
|
type GetAdminReq {
|
||||||
|
Id int64 `json:"id" form:"id"` // 用户ID(必填)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取详情响应(显式嵌套BaseResp)
|
||||||
|
type GetAdminResp {
|
||||||
|
BaseResp // 继承基础响应字段
|
||||||
|
Data AdminInfo `json:"data"` // 管理员详情数据
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 删除管理员相关
|
||||||
|
type DeleteAdminReq {
|
||||||
|
Id int64 `json:"id" form:"id"` // 用户ID(必填)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除完整响应(显式嵌套BaseResp,无额外数据)
|
||||||
|
type DeleteAdminResp {
|
||||||
|
BaseResp // 仅继承基础响应字段
|
||||||
|
}
|
||||||
|
|
||||||
|
// 管理员相关接口
|
||||||
|
@server (
|
||||||
|
group: admin
|
||||||
|
prefix: /api/admin
|
||||||
|
)
|
||||||
|
service admin-api {
|
||||||
|
@handler ListAdminHandler
|
||||||
|
get /admin/list (ListAdminReq) returns (ListAdminResp)
|
||||||
|
|
||||||
|
@handler GetAdminHandler
|
||||||
|
get /admin (GetAdminReq) returns (GetAdminResp)
|
||||||
|
|
||||||
|
@handler CreateAdminHandler
|
||||||
|
post /admin (CreateAdminReq) returns (CreateAdminResp)
|
||||||
|
|
||||||
|
@handler UpdateAdminHandler
|
||||||
|
put /admin (UpdateAdminReq) returns (UpdateAdminResp)
|
||||||
|
|
||||||
|
@handler DeleteAdminHandler
|
||||||
|
delete /admin (DeleteAdminReq) returns (DeleteAdminResp)
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user