mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[优化]base模块提出
This commit is contained in:
@@ -7,9 +7,9 @@ package api
|
||||
import (
|
||||
"pandax/apps/{{.PackageName}}/entity"
|
||||
"pandax/apps/{{.PackageName}}/services"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/utils"
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"github.com/XM-GO/PandaKit/restfulx"
|
||||
"github.com/XM-GO/PandaKit/utils"
|
||||
)
|
||||
|
||||
type {{.ClassName}}Api struct {
|
||||
@@ -23,16 +23,16 @@ 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 *ginx.ReqCtx) {
|
||||
func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *restfulx.ReqCtx) {
|
||||
data := entity.{{.ClassName}}{}
|
||||
pageNum := ginx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := ginx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
pageNum := restfulx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
pageSize := restfulx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
{{- range $index, $column := .Columns -}}
|
||||
{{- if eq $column.IsRequired "1" -}}
|
||||
{{- if eq $column.GoType "string" }}
|
||||
data.{{$column.GoField}} = rc.GinCtx.Query("{{$column.JsonField}}")
|
||||
{{- else if or (eq $column.GoType "int") (eq $column.GoType "int64") (eq $column.GoType "uint") (eq $column.GoType "uint64") -}}
|
||||
data.{{$column.GoField}} = ginx.QueryInt(rc.GinCtx, "{{$column.JsonField}}", 0)
|
||||
data.{{$column.GoField}} = restfulx.QueryInt(rc.GinCtx, "{{$column.JsonField}}", 0)
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
@@ -54,8 +54,8 @@ func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /{{.PackageName}}/{{.BusinessName}}/{{"{"}}{{.PkJsonField}}{{"}"}} [get]
|
||||
// @Security
|
||||
func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ginx.ReqCtx) {
|
||||
{{.PkJsonField}} := ginx.PathParamInt(rc.GinCtx, "{{.PkJsonField}}")
|
||||
func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *restfulx.ReqCtx) {
|
||||
{{.PkJsonField}} := restfulx.PathParamInt(rc.GinCtx, "{{.PkJsonField}}")
|
||||
p.{{.ClassName}}App.FindOne(int64({{.PkJsonField}}))
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||
// @Router /{{.PackageName}}/{{.BusinessName}} [post]
|
||||
// @Security X-TOKEN
|
||||
func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ginx.ReqCtx) {
|
||||
func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *restfulx.ReqCtx) {
|
||||
var data entity.{{.ClassName}}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, &data)
|
||||
restfulx.BindJsonAndValid(rc.GinCtx, &data)
|
||||
|
||||
p.{{.ClassName}}App.Insert(data)
|
||||
}
|
||||
@@ -86,9 +86,9 @@ func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *ginx.ReqCtx) {
|
||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||
// @Router /{{.PackageName}}/{{.BusinessName}} [put]
|
||||
// @Security X-TOKEN
|
||||
func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ginx.ReqCtx) {
|
||||
func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *restfulx.ReqCtx) {
|
||||
var data entity.{{.ClassName}}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, &data)
|
||||
restfulx.BindJsonAndValid(rc.GinCtx, &data)
|
||||
|
||||
p.{{.ClassName}}App.Update(data)
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *ginx.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 *ginx.ReqCtx) {
|
||||
func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *restfulx.ReqCtx) {
|
||||
|
||||
{{.PkJsonField}} := rc.GinCtx.Param("{{.PkJsonField}}")
|
||||
{{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}})
|
||||
|
||||
Reference in New Issue
Block a user