【更新】更新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,36 +2,61 @@ 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 InitPostRouter(router *gin.RouterGroup) {
func InitPostRouter(container *restful.Container) {
s := &api.PostApi{
PostApp: services.SysPostModelDao,
UserApp: services.SysUserModelDao,
RoleApp: services.SysRoleModelDao,
}
post := router.Group("post")
ws := new(restful.WebService)
ws.Path("/system/post").Produces(restful.MIME_JSON)
tags := []string{"post"}
post.GET("list", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取岗位分页列表").Handle(s.GetPostList)
})
ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取岗位分页列表").Handle(s.GetPostList)
}).
Doc("获取岗位分页列表").
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes([]entity.SysPost{}).
Returns(200, "OK", []entity.SysPost{}))
post.GET(":postId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取岗位信息").Handle(s.GetPost)
})
ws.Route(ws.GET("/{postId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取岗位信息").Handle(s.GetPost)
}).
Doc("获取岗位信息").
Param(ws.PathParameter("postId", "Id").DataType("int").DefaultValue("1")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(entity.SysPost{}). // on the response
Returns(200, "OK", entity.SysPost{}).
Returns(404, "Not Found", nil))
post.POST("", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("添加岗位信息").Handle(s.InsertPost)
})
ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("添加岗位信息").Handle(s.InsertPost)
}).
Doc("添加岗位信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysPost{})) // from the request
post.PUT("", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("修改岗位信息").Handle(s.UpdatePost)
})
ws.Route(ws.PUT("").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("修改岗位信息").Handle(s.UpdatePost)
}).
Doc("修改岗位信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysPost{})) // from the request
post.DELETE(":postId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("删除岗位信息").Handle(s.DeletePost)
})
ws.Route(ws.DELETE("/{postId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("删除岗位信息").Handle(s.DeletePost)
}).
Doc("删除岗位信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Param(ws.PathParameter("postId", "多id 1,2,3").DataType("string")))
container.Add(ws)
}