【更新】更新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,64 +2,107 @@ 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 InitDictRouter(router *gin.RouterGroup) {
func InitDictRouter(container *restful.Container) {
s := &api.DictApi{
DictType: services.SysDictTypeModelDao,
DictData: services.SysDictDataModelDao,
}
dict := router.Group("dict")
ws := new(restful.WebService)
ws.Path("/system/dict").Produces(restful.MIME_JSON)
tags := []string{"dict"}
dict.GET("type/list", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取字典类型分页列表").Handle(s.GetDictTypeList)
})
ws.Route(ws.GET("/type/list").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取字典类型分页列表").Handle(s.GetDictTypeList)
}).
Doc("获取字典类型分页列表").
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "OK", []entity.SysDictType{}))
dict.GET("type/:dictId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取字典类型信息").Handle(s.GetDictType)
})
ws.Route(ws.GET("/type/{dictId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取字典类型信息").Handle(s.GetDictType)
}).
Doc("获取字典类型信息").
Param(ws.PathParameter("dictId", "Id").DataType("int").DefaultValue("1")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "OK", []entity.SysDictType{}))
dict.POST("type", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("添加字典类型信息").Handle(s.InsertDictType)
})
ws.Route(ws.POST("/type").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("添加字典类型信息").Handle(s.InsertDictType)
}).
Doc("添加字典类型信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysDictType{}))
dict.PUT("type", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("修改字典类型信息").Handle(s.UpdateDictType)
})
ws.Route(ws.PUT("/type").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("修改字典类型信息").Handle(s.UpdateDictType)
}).
Doc("修改字典类型信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysDictType{}))
dict.DELETE("type/:dictId", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("删除字典类型信息").Handle(s.DeleteDictType)
})
ws.Route(ws.DELETE("/type/{dictId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("删除字典类型信息").Handle(s.DeleteDictType)
}).
Doc("删除字典类型信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Param(ws.PathParameter("dictId", "多id 1,2,3").DataType("string")))
dict.GET("type/export", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("导出字典类型信息").Handle(s.ExportDictType)
})
ws.Route(ws.GET("/type/export").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("导出字典类型信息").Handle(s.ExportDictType)
}).
Doc("导出字典类型信息").
Metadata(restfulspec.KeyOpenAPITags, tags))
dict.GET("data/list", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取字典数据分页列表").Handle(s.GetDictDataList)
})
ws.Route(ws.GET("/data/list").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取字典数据分页列表").Handle(s.GetDictDataList)
}).
Doc("获取字典数据分页列表").
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "OK", []entity.SysDictData{}))
dict.GET("data/type", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取字典数据列表通过字典类型").Handle(s.GetDictDataListByDictType)
})
ws.Route(ws.GET("/data/type").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取字典数据列表通过字典类型").Handle(s.GetDictDataListByDictType)
}).
Doc("获取字典数据列表通过字典类型").
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "OK", []entity.SysDictType{}))
dict.GET("data/:dictCode", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("获取字典数据信息").Handle(s.GetDictData)
})
ws.Route(ws.GET("/data/{dictCode}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("获取字典数据信息").Handle(s.GetDictData)
}).
Doc("获取字典数据信息").
Param(ws.PathParameter("dictCode", "dictCode").DataType("string")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "OK", []entity.SysDictType{}))
dict.POST("data", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("添加字典数据信息").Handle(s.InsertDictData)
})
ws.Route(ws.POST("/data").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("添加字典数据信息").Handle(s.InsertDictData)
}).
Doc("添加字典数据信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysDictData{}))
dict.PUT("data", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("修改字典数据信息").Handle(s.UpdateDictData)
})
ws.Route(ws.PUT("/data").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("修改字典数据信息").Handle(s.UpdateDictData)
}).
Doc("修改字典数据信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(entity.SysDictData{}))
dict.DELETE("data/:dictCode", func(c *gin.Context) {
restfulx.NewReqCtx(c).WithLog("删除字典数据信息").Handle(s.DeleteDictData)
})
ws.Route(ws.DELETE("data/{dictCode}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithLog("删除字典数据信息").Handle(s.DeleteDictData)
}).
Doc("删除字典数据信息").
Metadata(restfulspec.KeyOpenAPITags, tags).
Param(ws.PathParameter("dictCode", "多id 1,2,3").DataType("string")))
container.Add(ws)
}