mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
71 lines
2.4 KiB
Plaintext
71 lines
2.4 KiB
Plaintext
package api
|
|
// ==========================================================================
|
|
// 生成日期:{{.CreatedAt}}
|
|
// 生成路径: apps/{{.PackageName}}/api/{{.TableName}}.go
|
|
// 生成人:{{.FunctionAuthor}}
|
|
// ==========================================================================
|
|
import (
|
|
"github.com/XM-GO/PandaKit/restfulx"
|
|
|
|
"pandax/apps/{{.PackageName}}/entity"
|
|
"pandax/apps/{{.PackageName}}/services"
|
|
"github.com/XM-GO/PandaKit/utils"
|
|
)
|
|
|
|
type {{.ClassName}}Api struct {
|
|
{{.ClassName}}App services.{{.ClassName}}Model
|
|
}
|
|
|
|
// Get{{.ClassName}}List {{.FunctionName}}列表数据
|
|
func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *restfulx.ReqCtx) {
|
|
data := entity.{{.ClassName}}{}
|
|
pageNum := restfulx.QueryInt(rc, "pageNum", 1)
|
|
pageSize := restfulx.QueryInt(rc, "pageSize", 10)
|
|
{{- range $index, $column := .Columns -}}
|
|
{{- if eq $column.IsRequired "1" -}}
|
|
{{- if eq $column.GoType "string" }}
|
|
data.{{$column.GoField}} = restfulx.QueryParam(rc, "{{$column.JsonField}}")
|
|
{{- else if or (eq $column.GoType "int") (eq $column.GoType "int64") (eq $column.GoType "uint") (eq $column.GoType "uint64") -}}
|
|
data.{{$column.GoField}} = restfulx.QueryInt(rc, "{{$column.JsonField}}", 0)
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end }}
|
|
|
|
list, total := p.{{.ClassName}}App.FindListPage(pageNum, pageSize, data)
|
|
|
|
rc.ResData = map[string]interface{}{
|
|
"data": list,
|
|
"total": total,
|
|
"pageNum": pageNum,
|
|
"pageSize": pageSize,
|
|
}
|
|
}
|
|
|
|
// Get{{.ClassName}} 获取{{.FunctionName}}
|
|
func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *restfulx.ReqCtx) {
|
|
{{.PkJsonField}} := restfulx.PathParamInt(rc, "{{.PkJsonField}}")
|
|
p.{{.ClassName}}App.FindOne(int64({{.PkJsonField}}))
|
|
}
|
|
|
|
// Insert{{.ClassName}} 添加{{.FunctionName}}
|
|
func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *restfulx.ReqCtx) {
|
|
var data entity.{{.ClassName}}
|
|
restfulx.BindQuery(rc, &data)
|
|
|
|
p.{{.ClassName}}App.Insert(data)
|
|
}
|
|
|
|
// Update{{.ClassName}} 修改{{.FunctionName}}
|
|
func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *restfulx.ReqCtx) {
|
|
var data entity.{{.ClassName}}
|
|
restfulx.BindQuery(rc, &data)
|
|
|
|
p.{{.ClassName}}App.Update(data)
|
|
}
|
|
|
|
// Delete{{.ClassName}} 删除{{.FunctionName}}
|
|
func (p *{{.ClassName}}Api) Delete{{.ClassName}}(rc *restfulx.ReqCtx) {
|
|
{{.PkJsonField}} := restfulx.PathParam("{{.PkJsonField}}")
|
|
{{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}})
|
|
p.{{.ClassName}}App.Delete({{.PkJsonField}}s)
|
|
} |