mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-30 04:42:59 +00:00
The config page saves an unticked query box as "0", and the DTO and API templates tested IsQuery with a bare if, which is true for any non-empty string. A column ticked and then unticked became a filter of the generated list request and a documented query parameter anyway. They now require "1", as the TypeScript and Vue templates already do.
164 lines
5.2 KiB
Plaintext
164 lines
5.2 KiB
Plaintext
package dto
|
|
|
|
import (
|
|
{{- /*
|
|
$embed: the key is models.Model's own Id, so the model embeds it.
|
|
$pkType: the key's Go type, for the delete request's id list.
|
|
*/ -}}
|
|
{{- $embed := false -}}
|
|
{{- $pkType := "int" -}}
|
|
{{- range .Columns -}}{{- if .Pk -}}{{- $pkType = .GoType -}}{{- if and (eq .GoField "Id") (eq .GoType "int") -}}{{- $embed = true -}}{{- end -}}{{- end -}}{{- end -}}
|
|
{{- $bb := false -}}
|
|
{{- range .Columns -}}
|
|
{{- /* "1" exactly: the config page saves an unticked box as "0", which a bare if reads as true. */ -}}
|
|
{{- if eq .IsQuery "1" -}}
|
|
{{- if eq .GoType "time.Time" -}}{{- $bb = true -}}{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- range .Columns -}}
|
|
{{- if eq .GoField "CreatedAt" -}}
|
|
{{- else if eq .GoField "UpdatedAt" -}}
|
|
{{- else if eq .GoField "DeletedAt" -}}
|
|
{{- else -}}
|
|
{{- if eq .GoType "time.Time" -}}{{- $bb = true -}}{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- if eq $bb true }}
|
|
"time"
|
|
{{- end }}
|
|
|
|
"go-admin/app/{{.PackageName}}/models"
|
|
"go-admin/common/dto"
|
|
common "go-admin/common/models"
|
|
)
|
|
|
|
type {{.ClassName}}GetPageReq struct {
|
|
dto.Pagination `search:"-"`
|
|
{{- $tablename := .TBName -}}
|
|
{{- range .Columns -}}
|
|
{{- if eq .IsQuery "1" }}
|
|
{{.GoField}} {{.GoType}} `form:"{{.JsonField}}" search:"type:{{if eq .QueryType "EQ"}}exact{{ else if eq .QueryType "NE"}}iexact{{ else if eq .QueryType "LIKE"}}contains{{ else if eq .QueryType "GT"}}gt{{ else if eq .QueryType "GTE"}}gte{{ else if eq .QueryType "LT"}}lt{{ else if eq .QueryType "LTE"}}lte{{- end }};column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"`
|
|
{{- end }}
|
|
{{- end }}
|
|
{{.ClassName}}Order
|
|
}
|
|
|
|
type {{.ClassName}}Order struct {
|
|
{{ $tablename := .TBName }}
|
|
{{- range .Columns -}}
|
|
{{.GoField}} string `form:"{{.JsonField}}Order" search:"type:order;column:{{.ColumnName}};table:{{$tablename}}"`
|
|
{{ end }}
|
|
}
|
|
|
|
func (m *{{.ClassName}}GetPageReq) GetNeedSearch() interface{} {
|
|
return *m
|
|
}
|
|
|
|
type {{.ClassName}}InsertReq struct {
|
|
{{- range .Columns -}}
|
|
{{$x := .Pk}}
|
|
{{- if ($x) }}
|
|
{{.GoField}} {{.GoType}} `json:"{{if eq .GoType "int"}}-{{else}}{{.JsonField}}{{end}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
|
|
{{- else if eq .GoField "CreatedAt" -}}
|
|
{{- else if eq .GoField "UpdatedAt" -}}
|
|
{{- else if eq .GoField "DeletedAt" -}}
|
|
{{- else if eq .GoField "CreateBy" -}}
|
|
{{- else if eq .GoField "UpdateBy" -}}
|
|
{{- else }}
|
|
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
|
|
{{- end -}}
|
|
{{- end }}
|
|
common.ControlBy
|
|
}
|
|
|
|
func (s *{{.ClassName}}InsertReq) Generate(model *models.{{.ClassName}}) {
|
|
{{- range .Columns -}}
|
|
{{$x := .Pk}}
|
|
{{- if ($x) }}
|
|
{{- if $embed }}
|
|
if s.{{.GoField}} == 0 {
|
|
model.Model = common.Model{ {{.GoField}}: s.{{.GoField}} }
|
|
}
|
|
{{- else }}
|
|
model.{{.GoField}} = s.{{.GoField}}
|
|
{{- end }}
|
|
{{- else if eq .GoField "CreatedAt" -}}
|
|
{{- else if eq .GoField "UpdatedAt" -}}
|
|
{{- else if eq .GoField "DeletedAt" -}}
|
|
{{- else if eq .GoField "CreateBy"}}
|
|
model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁创建的
|
|
{{- else if eq .GoField "UpdateBy" -}}
|
|
{{- else }}
|
|
model.{{.GoField}} = s.{{.GoField}}
|
|
{{- end -}}
|
|
{{- end }}
|
|
}
|
|
|
|
func (s *{{.ClassName}}InsertReq) GetId() interface{} {
|
|
return s.{{.PkGoField}}
|
|
}
|
|
|
|
type {{.ClassName}}UpdateReq struct {
|
|
{{- range .Columns -}}
|
|
{{$x := .Pk}}
|
|
{{- if ($x) }}
|
|
{{.GoField}} {{.GoType}} `uri:"id" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
|
|
{{- else if eq .GoField "CreatedAt" -}}
|
|
{{- else if eq .GoField "UpdatedAt" -}}
|
|
{{- else if eq .GoField "DeletedAt" -}}
|
|
{{- else if eq .GoField "CreateBy" -}}
|
|
{{- else if eq .GoField "UpdateBy" -}}
|
|
{{- else }}
|
|
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
|
|
{{- end -}}
|
|
{{- end }}
|
|
common.ControlBy
|
|
}
|
|
|
|
func (s *{{.ClassName}}UpdateReq) Generate(model *models.{{.ClassName}}) {
|
|
{{- range .Columns -}}
|
|
{{$x := .Pk}}
|
|
{{- if ($x) }}
|
|
{{- if $embed }}
|
|
if s.{{.GoField}} == 0 {
|
|
model.Model = common.Model{ {{.GoField}}: s.{{.GoField}} }
|
|
}
|
|
{{- end }}
|
|
{{- else if eq .GoField "CreatedAt" -}}
|
|
{{- else if eq .GoField "UpdatedAt" -}}
|
|
{{- else if eq .GoField "DeletedAt" -}}
|
|
{{- else if eq .GoField "CreateBy" -}}
|
|
{{- else if eq .GoField "UpdateBy"}}
|
|
model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁更新的
|
|
{{- else }}
|
|
model.{{.GoField}} = s.{{.GoField}}
|
|
{{- end -}}
|
|
{{- end }}
|
|
}
|
|
|
|
func (s *{{.ClassName}}UpdateReq) GetId() interface{} {
|
|
return s.{{.PkGoField}}
|
|
}
|
|
|
|
// {{.ClassName}}GetReq 功能获取请求参数
|
|
type {{.ClassName}}GetReq struct {
|
|
{{- range .Columns -}}
|
|
{{$x := .Pk}}
|
|
{{- if ($x) }}
|
|
{{.GoField}} {{.GoType}} `uri:"id"`
|
|
{{- end }}
|
|
{{- end }}
|
|
}
|
|
func (s *{{.ClassName}}GetReq) GetId() interface{} {
|
|
return s.{{.PkGoField}}
|
|
}
|
|
|
|
// {{.ClassName}}DeleteReq 功能删除请求参数
|
|
type {{.ClassName}}DeleteReq struct {
|
|
Ids []{{$pkType}} `json:"ids"`
|
|
}
|
|
|
|
func (s *{{.ClassName}}DeleteReq) GetId() interface{} {
|
|
return s.Ids
|
|
}
|