【更新】更新restful

This commit is contained in:
PandaGoAdmin
2022-08-03 16:00:32 +08:00
parent 2cb23c0ecf
commit 6945277fdb
48 changed files with 1234 additions and 836 deletions

View File

@@ -2,49 +2,80 @@ package router
import (
"github.com/XM-GO/PandaKit/restfulx"
"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"
)
func InitRoleRouter(router *gin.RouterGroup) {
func InitRoleRouter(container *restful.Container) {
s := &api.RoleApi{
RoleApp: services.SysRoleModelDao,
RoleMenuApp: services.SysRoleMenuModelDao,
RoleDeptApp: services.SysRoleDeptModelDao,
UserApp: services.SysUserModelDao,
}
role := router.Group("role")
ws := new(restful.WebService)
ws.Path("/system/role").Produces(restful.MIME_JSON)
tags := []string{"role"}
role.GET("list", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取角色分页列表").Handle(s.GetRoleList)
})
ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取角色分页列表").Handle(s.GetRoleList)
}).
Doc("获取角色分页列表").
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes([]entity.SysRole{}).
Returns(200, "OK", []entity.SysRole{}))
role.GET(":roleId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取角色信息").Handle(s.GetRole)
})
ws.Route(ws.GET("/{roleId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取角色信息").Handle(s.GetRole)
}).
Doc("获取角色信息").
Param(ws.PathParameter("roleId", "Id").DataType("int").DefaultValue("1")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(entity.SysRole{}). // on the response
Returns(200, "OK", entity.SysRole{}).
Returns(404, "Not Found", nil))
role.POST("", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("添加角色信息").Handle(s.InsertRole)
})
ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("添加角色信息").Handle(s.InsertRole)
}).
Doc("添加角色信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysRole{})) // from the request
role.PUT("", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("修改角色信息").Handle(s.UpdateRole)
})
ws.Route(ws.PUT("").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("修改角色信息").Handle(s.UpdateRole)
}).
Doc("修改角色信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysRole{}))
role.PUT("changeStatus", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("修改角色状态").Handle(s.UpdateRoleStatus)
})
ws.Route(ws.PUT("/changeStatus").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("修改角色状态").Handle(s.UpdateRoleStatus)
}).
Doc("修改角色状态").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysRole{}))
role.PUT("dataScope", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("修改角色部门权限").Handle(s.UpdateRoleDataScope)
})
ws.Route(ws.PUT("/dataScope").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("修改角色部门权限").Handle(s.UpdateRoleDataScope)
}).
Doc("修改角色部门权限").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysRole{}))
role.DELETE(":roleId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("删除角色信息").Handle(s.DeleteRole)
})
ws.Route(ws.DELETE("/{roleId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("删除角色信息").Handle(s.DeleteRole)
}).
Doc("删除角色信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Param(ws.PathParameter("roleId", "多id 1,2,3").DataType("string")))
role.GET("export", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("导出角色信息").Handle(s.ExportRole)
})
ws.Route(ws.GET("/export").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("导出角色信息").Handle(s.ExportRole)
}).
Doc("导出角色信息").
Metadata(restfulspec.KeyOpenAPITags, tags))
}