feat: swagger

This commit is contained in:
Blizzard
2025-09-16 14:27:32 +08:00
parent 79c19bc47c
commit 237ac665e6
19 changed files with 4690 additions and 91 deletions
+22 -4
View File
@@ -17,7 +17,14 @@ var store = base64Captcha.DefaultMemStore
type AuthApi struct{}
// Login api
// Login
// @Tags 登录相关
// @Summary pc登录
// @accept application/json
// @Produce application/json
// @Param data body systemReq.Login true "用户名, 密码, 验证码,验证码id"
// @Success 200 {object} response.Response{msg=string} "登录成功"
// @Router /api/auth/login [post]
func (a *AuthApi) Login(c *gin.Context) {
var l systemReq.Login
err := c.ShouldBindJSON(&l)
@@ -39,7 +46,13 @@ func (a *AuthApi) Login(c *gin.Context) {
response.FailWithMsg("验证码错误", c)
}
// 登出
// Logout
// @Tags 登录相关
// @Summary pc登出
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "登出成功"
// @Router /api/auth/logout [get]
func (a *AuthApi) Logout(c *gin.Context) {
token := jwt.GetToken(c)
userId := jwt.GetUserId(c)
@@ -54,7 +67,12 @@ func (a *AuthApi) Logout(c *gin.Context) {
}
// Captcha api 生成验证码
// Captcha
// @Tags 登录相关
// @Summary 获取验证码
// @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.CaptchaRes} "获取验证码"
// @Router /api/auth/captcha [get]
func (u *AuthApi) Captcha(c *gin.Context) {
var driver = base64Captcha.DriverString{
Height: 80,
@@ -62,7 +80,7 @@ func (u *AuthApi) Captcha(c *gin.Context) {
NoiseCount: 2,
ShowLineOptions: 4,
Length: 4,
Source: "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM",
Source: "1234567890",
}
cp := base64Captcha.NewCaptcha(&driver, store)
+50 -9
View File
@@ -1,18 +1,28 @@
package system
import (
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"sundynix-go/global"
"sundynix-go/model/commom/request"
"sundynix-go/model/commom/response"
"sundynix-go/model/system"
systemReq "sundynix-go/model/system/request"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type ClientApi struct {
}
// SaveClient
// @Tags 客户端管理
// @Summary 创建client
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.Client true "client"
// @Success 200 {object} response.Response{msg=string} "创建client"
// @Router /api/client/save [post]
func (s *ClientApi) SaveClient(c *gin.Context) {
var client system.Client
err := c.ShouldBindJSON(&client)
@@ -29,6 +39,15 @@ func (s *ClientApi) SaveClient(c *gin.Context) {
response.OkWithMsg("保存客户端成功!", c)
}
// UpdateClient
// @Tags 客户端管理
// @Summary 更新client
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.Client true "client"
// @Success 200 {object} response.Response{msg=string} "更新client"
// @Router /api/client/update [post]
func (s *ClientApi) UpdateClient(c *gin.Context) {
var client system.Client
err := c.ShouldBindJSON(&client)
@@ -45,6 +64,15 @@ func (s *ClientApi) UpdateClient(c *gin.Context) {
response.OkWithMsg("更新客户端成功!", c)
}
// GetClientList
// @Tags 客户端管理
// @Summary 获取client列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body systemReq.GetClientList true "client"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取client列表"
// @Router /api/client/getClientList [post]
func (s *ClientApi) GetClientList(c *gin.Context) {
var pageInfo systemReq.GetClientList
err := c.ShouldBindJSON(&pageInfo)
@@ -66,6 +94,15 @@ func (s *ClientApi) GetClientList(c *gin.Context) {
}, c)
}
// Delete
// @Tags 客户端管理
// @Summary 删除client
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "ids"
// @Success 200 {object} response.Response{msg=string} "删除client"
// @Router /api/client/delete [post]
func (s *ClientApi) Delete(c *gin.Context) {
var ids request.IdsReq
err := c.ShouldBindJSON(&ids)
@@ -82,14 +119,18 @@ func (s *ClientApi) Delete(c *gin.Context) {
response.OkWithMsg("删除客户端成功!", c)
}
// Detail
// @Tags 客户端管理
// @Summary 获取client详情
// @Description id获取详情
// @Security ApiKeyAuth
// @Produce application/json
// @Param id query string true "id"
// @Success 200 {object} response.Response{data=system.Client,msg=string} "获取client详情"
// @Router /api/client/detail [get]
func (s *ClientApi) Detail(c *gin.Context) {
var idInfo request.GetById
err := c.ShouldBindJSON(&idInfo)
if err != nil {
response.FailWithMsg(err.Error(), c)
return
}
client, err := clientService.GetClientById(idInfo.ID)
id := c.Query("id")
client, err := clientService.GetClientById(id)
if err != nil {
global.Logger.Error("获取客户端详情失败!", zap.Error(err))
response.FailWithMsg(err.Error(), c)
+59
View File
@@ -14,6 +14,15 @@ import (
type MenuApi struct {
}
// SaveMenu
// @Tags 菜单管理
// @Summary 新增菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.Menu false "menu"
// @Success 200 {object} response.Response{msg=string} "新建菜单/按钮"
// @Router /api/menu/save [post]
func (m *MenuApi) SaveMenu(c *gin.Context) {
var menu system.Menu
err := c.ShouldBindJSON(&menu)
@@ -30,6 +39,15 @@ func (m *MenuApi) SaveMenu(c *gin.Context) {
}
}
// UpdateMenu
// @Tags 菜单管理
// @Summary 更新菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.Menu false "menu"
// @Success 200 {object} response.Response{msg=string} "更新菜单"
// @Router /menu/update [post]
func (m *MenuApi) UpdateMenu(c *gin.Context) {
var menu system.Menu
err := c.ShouldBindJSON(&menu)
@@ -46,6 +64,15 @@ func (m *MenuApi) UpdateMenu(c *gin.Context) {
}
}
// DeleteMenu
// @Tags 菜单管理
// @Summary 删除menu
// @Description 删除menu
// @Security ApiKeyAuth
// @Produce application/json
// @Param id query string true "id"
// @Success 200 {object} response.Response{msg=string} "详情"
// @Router /api/menu/delete [get]
func (m *MenuApi) DeleteMenu(c *gin.Context) {
id := c.Query("id")
err := menuService.DeleteMenu(id)
@@ -57,6 +84,15 @@ func (m *MenuApi) DeleteMenu(c *gin.Context) {
response.OkWithMsg("删除菜单成功!", c)
}
// Detail
// @Tags 菜单管理
// @Summary 获取menu详情
// @Description id获取详情
// @Security ApiKeyAuth
// @Produce application/json
// @Param id query string true "id"
// @Success 200 {object} response.Response{data=system.Menu,msg=string} "详情"
// @Router /api/menu/detail [get]
func (m *MenuApi) Detail(c *gin.Context) {
id := c.Query("id")
menu, err := menuService.GetMenuById(id)
@@ -68,6 +104,15 @@ func (m *MenuApi) Detail(c *gin.Context) {
response.OkWithData(menu, c)
}
// GetAllMenuTree
// @Tags 菜单管理
// @Summary 获取所有菜单树
// @Security ApiKeyAuth
// @Accept json
// @Produce json
// @Param data body systemReq.GetMenuTree true "菜单信息"
// @Success 200 {object} response.Response{data=[]system.Menu,msg=string} "获取所有菜单树"
// @Router /api/menu/getAllMenuTree [post]
func (m *MenuApi) GetAllMenuTree(c *gin.Context) {
var param systemReq.GetMenuTree
err := c.ShouldBindJSON(&param)
@@ -84,10 +129,24 @@ func (m *MenuApi) GetAllMenuTree(c *gin.Context) {
response.OkWithData(menus, c)
}
// GetUserMenuTree
// @Tags 菜单管理
// @Summary 用户菜单数据
// @Security ApiKeyAuth
// @Produce json
// @Success 200 {object} response.Response{data=[]system.Menu,msg=string} "用户菜单数据"
// @Router /api/menu/getUserMenuTree [get]
func (m *MenuApi) GetUserMenuTree(c *gin.Context) {
}
// Route
// @Tags 菜单管理
// @Summary 用户路由
// @Security ApiKeyAuth
// @Produce json
// @Success 200 {object} response.Response{data=[]system.Menu,msg=string} "用户route"
// @Router /api/menu/route [get]
func (m *MenuApi) Route(c *gin.Context) {
userId := jwt.GetUserId(c)
routes, err := menuService.GetUserRoutes(userId)
+53
View File
@@ -14,6 +14,15 @@ import (
type RoleApi struct {
}
// SaveRole
// @tags 角色管理
// @Summary 创建角色
// @Security ApiKeyAuth
// @accept json
// @Produce json
// @Param data body system.Role true "角色信息"
// @Success 200 {object} response.Response
// @Router /api/role/save [post]
func (a *RoleApi) SaveRole(context *gin.Context) {
var role system.Role
err := context.ShouldBindJSON(&role)
@@ -30,6 +39,15 @@ func (a *RoleApi) SaveRole(context *gin.Context) {
response.OkWithMsg("保存角色成功!", context)
}
// UpdateRole
// @tags 角色管理
// @Summary 修改角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.Role true "角色ID"
// @Success 200 {object} response.Response"
// @Router /api/role/update [post]
func (a *RoleApi) UpdateRole(context *gin.Context) {
var role system.Role
err := context.ShouldBindJSON(&role)
@@ -46,6 +64,15 @@ func (a *RoleApi) UpdateRole(context *gin.Context) {
response.OkWithMsg("更新角色成功!", context)
}
// GetRoleList
// @tags 角色管理
// @Summary 获取角色列表
// @Description 获取角色列表
// @Accept application/json
// @Produce application/json
// @Param data body systemreq.GetRoleList true "页码, 每页大小, 搜索条件"
// @success 200 {object} response.Response{data=response.PageResult,msg=string} "获取角色列表,返回包括列表,总数,页码,每页大小"
// @Router /api/role/getRoleList [post]
func (a *RoleApi) GetRoleList(c *gin.Context) {
var pageInfo systemreq.GetRoleList
err := c.ShouldBindJSON(&pageInfo)
@@ -66,6 +93,15 @@ func (a *RoleApi) GetRoleList(c *gin.Context) {
}, c)
}
// Delete
// @Tags 角色管理
// @Summary 删除角色
// @Description 删除角色
// @Accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除角色"
// @Success 200 {object} response.Response{msg=string} "删除角色"
// @Router /api/role/delete [post]
func (a *RoleApi) Delete(context *gin.Context) {
var ids request.IdsReq
err := context.ShouldBindJSON(&ids)
@@ -82,6 +118,14 @@ func (a *RoleApi) Delete(context *gin.Context) {
response.OkWithMsg("删除角色成功!", context)
}
// Detail
// @Tags 角色管理
// @Summary 角色详情
// @Security ApiKeyAuth
// @Produce application/json
// @Param id query string true "id"
// @Success 200 {object} response.Response{data=system.Role} "角色详情"
// @Router /api/role/detail [get]
func (a *RoleApi) Detail(context *gin.Context) {
id := context.Query("id")
role, err := roleService.GetRoleById(id)
@@ -93,6 +137,15 @@ func (a *RoleApi) Detail(context *gin.Context) {
response.OkWithData(role, context)
}
// GrantMenu
// @tags 角色管理
// @Summary 授权菜单给角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body systemreq.GrantMenu true "授权菜单给角色"
// @success 200 {object} response.Response "授权菜单给角色"
// @Router /api/role/grantMenu [post]
func (a *RoleApi) GrantMenu(c *gin.Context) {
var grantMenu systemreq.GrantMenu
err := c.ShouldBindJSON(&grantMenu)
+63
View File
@@ -14,6 +14,15 @@ import (
type UserApi struct {
}
// SaveUser
// @tags 用户管理
// @Summary 新增用户
// @Security ApiKeyAuth
// @accept json
// @Produce json
// @Param data body system.User true "用户信息"
// @Success 200 {object} response.Response "{"code": 200, "data": {}, "msg": "添加成功"}"
// @Router /api/user/save [post]
func (u *UserApi) SaveUser(c *gin.Context) {
var user system.User
err := c.ShouldBindJSON(&user)
@@ -29,6 +38,15 @@ func (u *UserApi) SaveUser(c *gin.Context) {
}
}
// UpdateUser
// @tags 用户管理
// @Summary 更新用户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.User true "用户ID,用户信息"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/user/update [post]
func (u *UserApi) UpdateUser(c *gin.Context) {
var user system.User
err := c.ShouldBindJSON(&user)
@@ -44,6 +62,15 @@ func (u *UserApi) UpdateUser(c *gin.Context) {
}
}
// GetUserList
// @tags 用户管理
// @Summary 获取用户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body systemReq.GetUserList true "页码, 每页大小, 搜索条件"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取用户列表,返回包括列表,总数,页码,每页大小"
// @Router /api/user/getUserList [post]
func (u *UserApi) GetUserList(c *gin.Context) {
var pageInfo systemReq.GetUserList
err := c.ShouldBindJSON(&pageInfo)
@@ -65,6 +92,15 @@ func (u *UserApi) GetUserList(c *gin.Context) {
}, c)
}
// Delete
// @Tags 用户管理
// @Summary 删除用户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除用户"
// @Success 200 {object} response.Response{msg=string} "删除用户"
// @Router /api/user/delete [post]
func (u *UserApi) Delete(c *gin.Context) {
var ids request.IdsReq
err := c.ShouldBindJSON(&ids)
@@ -81,6 +117,14 @@ func (u *UserApi) Delete(c *gin.Context) {
response.OkWithMsg("删除用户成功!", c)
}
// Detail
// @Tags 用户管理
// @Summary 获取用户详情
// @Security ApiKeyAuth
// @Produce application/json
// @Param id query string true "id"
// @Success 200 {object} response.Response{data=system.User} "获取用户详情成功"
// @Router /api/user/detail [get]
func (u *UserApi) Detail(c *gin.Context) {
id := c.Query("id")
user, err := userService.GetUserById(id)
@@ -92,6 +136,16 @@ func (u *UserApi) Detail(c *gin.Context) {
response.OkWithData(user, c)
}
// ChangePassword
// @Tags 用户管理
// @Summary 修改密码
// @Security ApiKeyAuth
// @Description 修改密码
// @accept json
// @Produce application/json
// @Param data body request.ChangePwd true "用户id"
// @Success 200 {object} response.Response{data=system.User} "修改密码成功"
// @Router /api/user/changePassword [post]
func (u *UserApi) ChangePassword(c *gin.Context) {
var changePwd systemReq.ChangePwd
err := c.ShouldBindJSON(&changePwd)
@@ -108,6 +162,15 @@ func (u *UserApi) ChangePassword(c *gin.Context) {
response.OkWithMsg("修改密码成功", c)
}
// GrantRole
// @Tags 用户管理
// @Summary 给用户分配角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body systemReq.GrantRole true "用户ID, 角色ID"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/user/grantRole [post]
func (u *UserApi) GrantRole(c *gin.Context) {
var grantRole systemReq.GrantRole
err := c.ShouldBindJSON(&grantRole)