[优化]restful

This commit is contained in:
PandaGoAdmin
2022-08-03 21:46:40 +08:00
parent 518a3de903
commit 0f08bac600
12 changed files with 447 additions and 210 deletions

View File

@@ -1,45 +1,82 @@
package router
import (
"github.com/XM-GO/PandaKit/restfulx"
restfulspec "github.com/emicklei/go-restful-openapi/v2"
"github.com/emicklei/go-restful/v3"
"pandax/apps/job/api"
"pandax/apps/job/entity"
"pandax/apps/job/services"
)
func InitJobRouter(container *restful.Container) {
// 登录日志
/*jobApi := &api.JobApi{
s := &api.JobApi{
JobApp: services.JobModelDao,
}
job := router.Group("job")
job.GET("list", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取Job列表").Handle(jobApi.GetJobList)
})
ws := new(restful.WebService)
ws.Path("/job").Produces(restful.MIME_JSON)
tags := []string{"job"}
job.GET(":jobId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取Job信息").Handle(jobApi.GetJob)
})
ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取Job列表").Handle(s.GetJobList)
}).
Doc("获取Job列表").
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes([]entity.SysJob{}).
Returns(200, "OK", []entity.SysJob{}))
job.POST("", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("添加Job信息").Handle(jobApi.CreateJob)
})
ws.Route(ws.GET("/{jobId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取Job列表").Handle(s.GetJob)
}).
Doc("获取Job列表").
Param(ws.PathParameter("jobId", "Id").DataType("int").DefaultValue("1")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(entity.SysJob{}). // on the response
Returns(200, "OK", entity.SysJob{}).
Returns(404, "Not Found", nil))
job.PUT("", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("修改Job信息").Handle(jobApi.UpdateJob)
})
ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("添加Job信息").Handle(s.CreateJob)
}).
Doc("添加Job信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysJob{})) // from the request
job.DELETE(":jobId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("删除Job信息").Handle(jobApi.DeleteJob)
})
ws.Route(ws.PUT("").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("修改Job信息").Handle(s.UpdateJob)
}).
Doc("修改Job信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysJob{})) // from the request
job.GET("/stop/:jobId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("停止一个job").Handle(jobApi.StopJobForService)
})
ws.Route(ws.DELETE("/{jobId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("删除Job信息").Handle(s.DeleteJob)
}).
Doc("删除Job信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Param(ws.PathParameter("jobId", "多id 1,2,3").DataType("string")))
job.GET("/start/:jobId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("开启一个job").Handle(jobApi.StartJobForService)
})
ws.Route(ws.GET("/stop/{jobId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("停止一个job").Handle(s.StopJobForService)
}).
Doc("停止一个job").
Param(ws.PathParameter("jobId", "Id").DataType("int")).
Metadata(restfulspec.KeyOpenAPITags, tags))
job.PUT("/changeStatus", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("修改状态").Handle(jobApi.UpdateStatusJob)
})*/
ws.Route(ws.GET("/start/{jobId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("开启一个job").Handle(s.StartJobForService)
}).
Doc("开启一个job").
Param(ws.PathParameter("jobId", "Id").DataType("int")).
Metadata(restfulspec.KeyOpenAPITags, tags))
ws.Route(ws.GET("/changeStatus").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("修改状态").Handle(s.UpdateStatusJob)
}).
Doc("修改状态").
Metadata(restfulspec.KeyOpenAPITags, tags))
container.Add(ws)
}