【更新】更新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,44 +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 InitDeptRouter(router *gin.RouterGroup) {
r := &api.DeptApi{
func InitDeptRouter(container *restful.Container) {
s := &api.DeptApi{
DeptApp: services.SysDeptModelDao,
RoleApp: services.SysRoleModelDao,
UserApp: services.SysUserModelDao,
}
dept := router.Group("dept")
dept.GET("roleDeptTreeSelect/:roleId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取角色部门树").Handle(r.GetDeptTreeRoleSelect)
})
ws := new(restful.WebService)
ws.Path("/system/dept").Produces(restful.MIME_JSON)
tags := []string{"dept"}
dept.GET("deptTree", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取所有部门树").Handle(r.GetDeptTree)
})
ws.Route(ws.GET("/roleDeptTreeSelect/{roleId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取角色部门树").Handle(s.GetDeptTreeRoleSelect)
}).
Doc("获取角色部门树").
Param(ws.PathParameter("roleId", "角色Id").DataType("int").DefaultValue("1")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(map[string]any{}). // on the response
Returns(404, "Not Found", nil))
dept.GET("list", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取部门列表").Handle(r.GetDeptList)
})
ws.Route(ws.GET("/deptTree").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取所有部门树").Handle(s.GetDeptTree)
}).
Doc("获取所有部门树").
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes([]entity.SysDept{}). // on the response
Returns(404, "Not Found", nil))
dept.GET(":deptId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取部门信息").Handle(r.GetDept)
})
ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取部门列表").Handle(s.GetDeptList)
}).
Doc("获取部门列表").
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes([]entity.SysDept{}).
Returns(200, "OK", []entity.SysDept{}))
dept.POST("", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("添加部门信息").Handle(r.InsertDept)
})
ws.Route(ws.GET("/{deptId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取部门信息").Handle(s.GetDept)
}).
Doc("获取部门信息").
Param(ws.PathParameter("deptId", "部门Id").DataType("int").DefaultValue("1")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(entity.SysDept{}). // on the response
Returns(200, "OK", entity.SysDept{}).
Returns(404, "Not Found", nil))
dept.PUT("", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("修改部门信息").Handle(r.UpdateDept)
})
ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("添加部门信息").Handle(s.InsertDept)
}).
Doc("添加部门信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysDept{})) // from the request
ws.Route(ws.PUT("").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("修改部门信息").Handle(s.UpdateDept)
}).
Doc("修改部门信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysDept{})) // from the request
ws.Route(ws.DELETE("/{deptId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("删除部门信息").Handle(s.DeleteDept)
}).
Doc("删除部门信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Param(ws.PathParameter("deptId", "多id 1,2,3").DataType("int")))
container.Add(ws)
dept.DELETE(":deptId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("删除部门信息").Handle(r.DeleteDept)
})
}