mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
108 lines
4.0 KiB
Plaintext
108 lines
4.0 KiB
Plaintext
package api
|
|
// ==========================================================================
|
|
// 生成日期:{{.CreatedAt}}
|
|
// 生成路径: apps/{{.PackageName}}/api/{{.TableName}}.go
|
|
// 生成人:{{.FunctionAuthor}}
|
|
// ==========================================================================
|
|
import (
|
|
"pandax/apps/{{.PackageName}}/entity"
|
|
"pandax/apps/{{.PackageName}}/services"
|
|
"github.com/XM-GO/PandaKit/restfulx"
|
|
"github.com/XM-GO/PandaKit/restfulx"
|
|
"github.com/XM-GO/PandaKit/utils"
|
|
)
|
|
|
|
type {{.ClassName}}Api struct {
|
|
{{.ClassName}}App services.{{.ClassName}}Model
|
|
}
|
|
|
|
// @Summary {{.FunctionName}}列表数据
|
|
// @Tags {{.FunctionName}}
|
|
// @Param pageSize query int false "页条数"
|
|
// @Param pageNum query int false "页码"
|
|
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
|
// @Router /{{.PackageName}}/{{.BusinessName}}/list [get]
|
|
// @Security
|
|
func (p *{{.ClassName}}Api) Get{{.ClassName}}List(rc *restfulx.ReqCtx) {
|
|
data := entity.{{.ClassName}}{}
|
|
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}} = restfulx.QueryInt(rc.GinCtx, "{{$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,
|
|
}
|
|
}
|
|
|
|
// @Summary 获取{{.FunctionName}}
|
|
// @Description 获取JSON
|
|
// @Tags {{.FunctionName}}
|
|
// @Param {{.PkJsonField}} path int true "{{.PkJsonField}}"
|
|
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
|
// @Router /{{.PackageName}}/{{.BusinessName}}/{{"{"}}{{.PkJsonField}}{{"}"}} [get]
|
|
// @Security
|
|
func (p *{{.ClassName}}Api) Get{{.ClassName}}(rc *restfulx.ReqCtx) {
|
|
{{.PkJsonField}} := restfulx.PathParamInt(rc.GinCtx, "{{.PkJsonField}}")
|
|
p.{{.ClassName}}App.FindOne(int64({{.PkJsonField}}))
|
|
}
|
|
|
|
// @Summary 添加{{.FunctionName}}
|
|
// @Description 获取JSON
|
|
// @Tags {{.FunctionName}}
|
|
// @Accept application/json
|
|
// @Product application/json
|
|
// @Param data body entity.{{.ClassName}} true "data"
|
|
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
|
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
|
// @Router /{{.PackageName}}/{{.BusinessName}} [post]
|
|
// @Security X-TOKEN
|
|
func (p *{{.ClassName}}Api) Insert{{.ClassName}}(rc *restfulx.ReqCtx) {
|
|
var data entity.{{.ClassName}}
|
|
restfulx.BindJsonAndValid(rc.GinCtx, &data)
|
|
|
|
p.{{.ClassName}}App.Insert(data)
|
|
}
|
|
|
|
// @Summary 修改{{.FunctionName}}
|
|
// @Description 获取JSON
|
|
// @Tags {{.FunctionName}}
|
|
// @Accept application/json
|
|
// @Product application/json
|
|
// @Param data body entity.{{.ClassName}} true "body"
|
|
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
|
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
|
// @Router /{{.PackageName}}/{{.BusinessName}} [put]
|
|
// @Security X-TOKEN
|
|
func (p *{{.ClassName}}Api) Update{{.ClassName}}(rc *restfulx.ReqCtx) {
|
|
var data entity.{{.ClassName}}
|
|
restfulx.BindJsonAndValid(rc.GinCtx, &data)
|
|
|
|
p.{{.ClassName}}App.Update(data)
|
|
}
|
|
|
|
// @Summary 删除{{.FunctionName}}
|
|
// @Description 删除数据
|
|
// @Tags {{.FunctionName}}
|
|
// @Param {{.PkJsonField}} path string true "{{.PkJsonField}}"
|
|
// @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 *restfulx.ReqCtx) {
|
|
|
|
{{.PkJsonField}} := rc.GinCtx.Param("{{.PkJsonField}}")
|
|
{{.PkJsonField}}s := utils.IdsStrToIdsIntGroup({{.PkJsonField}})
|
|
p.{{.ClassName}}App.Delete({{.PkJsonField}}s)
|
|
} |