【更新】更新

This commit is contained in:
PandaGoAdmin
2022-08-02 17:19:14 +08:00
parent 791a23306c
commit 0555922a90
50 changed files with 678 additions and 450 deletions

View File

@@ -7,7 +7,7 @@ package api
import (
"pandax/apps/{{.PackageName}}/entity"
"pandax/apps/{{.PackageName}}/services"
"pandax/base/ctx"
"pandax/base/ginx"
"pandax/base/ginx"
"pandax/base/utils"
)
@@ -23,7 +23,7 @@ type {{.ClassName}}Api struct {
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /{{.PackageName}}/{{.BusinessName}}/list [get]
// @Security
func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *ctx.ReqCtx) {
func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *ginx.ReqCtx) {
data := entity.{{.ClassName}}{}
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
@@ -54,7 +54,7 @@ func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *ctx.ReqCtx) {
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Router /{{.PackageName}}/{{.BusinessName}}/{{"{"}}{{.PkJsonField}}{{"}"}} [get]
// @Security
func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ctx.ReqCtx) {
func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ginx.ReqCtx) {
{{.PkJsonField}} := ginx.PathParamInt(rc.GinCtx, "{{.PkJsonField}}")
p.{{.ClassName}}App.FindOne(int64({{.PkJsonField}}))
}
@@ -69,7 +69,7 @@ func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ctx.ReqCtx) {
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
// @Router /{{.PackageName}}/{{.BusinessName}} [post]
// @Security X-TOKEN
func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ctx.ReqCtx) {
func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ginx.ReqCtx) {
var data entity.{{.ClassName}}
ginx.BindJsonAndValid(rc.GinCtx, &data)
@@ -86,7 +86,7 @@ func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ctx.ReqCtx) {
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
// @Router /{{.PackageName}}/{{.BusinessName}} [put]
// @Security X-TOKEN
func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ctx.ReqCtx) {
func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ginx.ReqCtx) {
var data entity.{{.ClassName}}
ginx.BindJsonAndValid(rc.GinCtx, &data)
@@ -100,7 +100,7 @@ func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ctx.ReqCtx) {
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
// @Router /{{.PackageName}}/{{.BusinessName}}/{{"{"}}{{.PkJsonField}}{{"}"}} [delete]
func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *ctx.ReqCtx) {
func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *ginx.ReqCtx) {
{{.PkJsonField}} := rc.GinCtx.Param("{{.PkJsonField}}")
{{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}})

View File

@@ -9,7 +9,7 @@ import (
"github.com/gin-gonic/gin"
"pandax/apps/{{.PackageName}}/api"
"pandax/apps/{{.PackageName}}/services"
"pandax/base/ctx"
"pandax/base/ginx"
)
func Init{{.ClassName}}Router(router *gin.RouterGroup) {
@@ -18,29 +18,29 @@ func Init{{.ClassName}}Router(router *gin.RouterGroup) {
}
routerGroup := router.Group("{{.BusinessName}}")
{{.ClassName}}ListLog := ctx.NewLogInfo("获取{{.FunctionName}}分页列表")
{{.ClassName}}ListLog := ginx.NewLogInfo("获取{{.FunctionName}}分页列表")
routerGroup.GET("list", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog({{.ClassName}}ListLog).Handle(s.Get{{.ClassName}}List)
ginx.NewReqCtx(c).WithLog({{.ClassName}}ListLog).Handle(s.Get{{.ClassName}}List)
})
{{.ClassName}}Log := ctx.NewLogInfo("获取{{.FunctionName}}信息")
{{.ClassName}}Log := ginx.NewLogInfo("获取{{.FunctionName}}信息")
routerGroup.GET(":{{.PkJsonField}}", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog({{.ClassName}}Log).Handle(s.Get{{.ClassName}})
ginx.NewReqCtx(c).WithLog({{.ClassName}}Log).Handle(s.Get{{.ClassName}})
})
insert{{.ClassName}}Log := ctx.NewLogInfo("添加{{.FunctionName}}信息")
insert{{.ClassName}}Log := ginx.NewLogInfo("添加{{.FunctionName}}信息")
routerGroup.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(insert{{.ClassName}}Log).Handle(s.Insert{{.ClassName}})
ginx.NewReqCtx(c).WithLog(insert{{.ClassName}}Log).Handle(s.Insert{{.ClassName}})
})
update{{.ClassName}}Log := ctx.NewLogInfo("修改{{.FunctionName}}信息")
update{{.ClassName}}Log := ginx.NewLogInfo("修改{{.FunctionName}}信息")
routerGroup.PUT("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(update{{.ClassName}}Log).Handle(s.Update{{.ClassName}})
ginx.NewReqCtx(c).WithLog(update{{.ClassName}}Log).Handle(s.Update{{.ClassName}})
})
delete{{.ClassName}}Log := ctx.NewLogInfo("删除{{.FunctionName}}信息")
delete{{.ClassName}}Log := ginx.NewLogInfo("删除{{.FunctionName}}信息")
routerGroup.DELETE(":{{.PkJsonField}}", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delete{{.ClassName}}Log).Handle(s.Delete{{.ClassName}})
ginx.NewReqCtx(c).WithLog(delete{{.ClassName}}Log).Handle(s.Delete{{.ClassName}})
})
}