mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 10:58:35 +08:00
【更新】更新restful
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
restfulspec "github.com/emicklei/go-restful-openapi/v2"
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"pandax/apps/system/api"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/apps/system/services"
|
||||
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
logServices "pandax/apps/log/services"
|
||||
)
|
||||
|
||||
func InitUserRouter(router *gin.RouterGroup) {
|
||||
func InitUserRouter(container *restful.Container) {
|
||||
s := &api.UserApi{
|
||||
RoleApp: services.SysRoleModelDao,
|
||||
MenuApp: services.SysMenuModelDao,
|
||||
@@ -19,61 +21,112 @@ func InitUserRouter(router *gin.RouterGroup) {
|
||||
DeptApp: services.SysDeptModelDao,
|
||||
PostApp: services.SysPostModelDao,
|
||||
}
|
||||
user := router.Group("user")
|
||||
// 获取验证码
|
||||
user.GET("getCaptcha", s.GenerateCaptcha)
|
||||
ws := new(restful.WebService)
|
||||
ws.Path("/system/user").Produces(restful.MIME_JSON)
|
||||
tags := []string{"user"}
|
||||
|
||||
user.POST("login", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("登录").WithNeedToken(false).WithNeedCasbin(false).Handle(s.Login)
|
||||
})
|
||||
user.GET("auth", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("认证信息").WithNeedCasbin(false).Handle(s.Auth)
|
||||
})
|
||||
user.POST("logout", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("退出登录").WithNeedToken(false).WithNeedCasbin(false).Handle(s.LogOut)
|
||||
})
|
||||
ws.Route(ws.GET("/getCaptcha").To(s.GenerateCaptcha).Doc("获取验证码"))
|
||||
|
||||
user.GET("list", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("得到用户分页列表").Handle(s.GetSysUserList)
|
||||
})
|
||||
ws.Route(ws.POST("/login").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithNeedToken(false).WithNeedCasbin(false).WithLog("登录").Handle(s.Login)
|
||||
}).
|
||||
Doc("登录").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Reads(entity.SysUser{})) // from the request
|
||||
|
||||
user.POST("avatar", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("修改用户头像").Handle(s.InsetSysUserAvatar)
|
||||
})
|
||||
ws.Route(ws.POST("/logout").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithNeedToken(false).WithNeedCasbin(false).WithLog("退出登录").Handle(s.LogOut)
|
||||
}).
|
||||
Doc("退出登录").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags))
|
||||
|
||||
user.PUT("pwd", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("修改用户密码").Handle(s.SysUserUpdatePwd)
|
||||
})
|
||||
ws.Route(ws.GET("/auth").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithNeedCasbin(false).WithLog("认证信息").Handle(s.Auth)
|
||||
}).
|
||||
Doc("认证信息").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Writes(entity.SysUser{}).
|
||||
Returns(200, "OK", entity.SysUser{}))
|
||||
|
||||
user.GET("getById/:userId", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("获取用户信息").Handle(s.GetSysUser)
|
||||
})
|
||||
ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("得到用户分页列表").Handle(s.GetSysUserList)
|
||||
}).
|
||||
Doc("得到用户分页列表").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Writes([]entity.SysUser{}).
|
||||
Returns(200, "OK", []entity.SysUser{}))
|
||||
|
||||
user.GET("getInit", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("获取初始化角色岗位信息(添加用户初始化)").Handle(s.GetSysUserInit)
|
||||
})
|
||||
ws.Route(ws.GET("/getById/{userId}").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取用户信息").Handle(s.GetSysUser)
|
||||
}).
|
||||
Doc("获取用户信息").
|
||||
Param(ws.PathParameter("userId", "Id").DataType("int").DefaultValue("1")).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Writes(entity.SysUser{}). // on the response
|
||||
Returns(200, "OK", entity.SysUser{}).
|
||||
Returns(404, "Not Found", nil))
|
||||
|
||||
user.GET("getRoPo", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("获取用户角色岗位信息(添加用户初始化)").Handle(s.GetUserRolePost)
|
||||
})
|
||||
ws.Route(ws.GET("/getInit").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取初始化角色岗位信息(添加用户初始化)").Handle(s.GetSysUserInit)
|
||||
}).
|
||||
Doc("获取初始化角色岗位信息(添加用户初始化)").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Writes(entity.SysUser{}). // on the response
|
||||
Returns(200, "OK", entity.SysUser{}).
|
||||
Returns(404, "Not Found", nil))
|
||||
|
||||
user.POST("", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("添加用户信息").Handle(s.InsertSysUser)
|
||||
})
|
||||
ws.Route(ws.GET("/getRoPo").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取用户角色岗位信息(添加用户初始化)").Handle(s.GetUserRolePost)
|
||||
}).
|
||||
Doc("获取用户角色岗位信息(添加用户初始化)").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Returns(200, "OK", entity.SysUser{}).
|
||||
Returns(404, "Not Found", nil))
|
||||
|
||||
user.PUT("", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("修改用户信息").Handle(s.UpdateSysUser)
|
||||
})
|
||||
ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("添加用户信息").Handle(s.InsertSysUser)
|
||||
}).
|
||||
Doc("添加用户信息").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Reads(entity.SysUser{})) // from the request
|
||||
|
||||
user.PUT("changeStatus", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("修改用户状态").Handle(s.UpdateSysUserStu)
|
||||
})
|
||||
ws.Route(ws.PUT("").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("修改用户信息").Handle(s.UpdateSysUser)
|
||||
}).
|
||||
Doc("修改用户信息").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags)) // from the request
|
||||
|
||||
user.DELETE(":userId", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("删除用户信息").Handle(s.DeleteSysUser)
|
||||
})
|
||||
ws.Route(ws.PUT("/changeStatus").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("修改用户状态").Handle(s.UpdateSysUserStu)
|
||||
}).
|
||||
Doc("修改用户状态").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags)) // from the request
|
||||
|
||||
ws.Route(ws.DELETE("/{userId}").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("删除用户信息").Handle(s.DeleteSysUser)
|
||||
}).
|
||||
Doc("删除用户信息").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Param(ws.PathParameter("userId", "多id 1,2,3").DataType("string")))
|
||||
|
||||
ws.Route(ws.POST("/avatar").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("修改用户头像").Handle(s.InsetSysUserAvatar)
|
||||
}).
|
||||
Doc("修改用户头像").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags))
|
||||
|
||||
ws.Route(ws.PUT("pwd").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("修改用户密码").Handle(s.SysUserUpdatePwd)
|
||||
}).
|
||||
Doc("修改用户密码").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags))
|
||||
|
||||
ws.Route(ws.GET("/export").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("导出用户信息").Handle(s.ExportUser)
|
||||
}).
|
||||
Doc("导出用户信息").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags))
|
||||
|
||||
container.Add(ws)
|
||||
|
||||
user.GET("export", func(c *gin.Context) {
|
||||
restfulx.NewReqCtx(c).WithLog("导出用户信息").Handle(s.ExportUser)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user