fix🐛: treat a column saved with isQuery "0" as not queryable

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.
This commit is contained in:
zhangwenjian
2026-09-27 16:07:09 +08:00
parent d30b9c103f
commit de33e527fc
2 changed files with 4 additions and 6 deletions
+3 -4
View File
@@ -10,8 +10,8 @@ import (
{{- range .Columns -}}{{- if .Pk -}}{{- $pkType = .GoType -}}{{- if and (eq .GoField "Id") (eq .GoType "int") -}}{{- $embed = true -}}{{- end -}}{{- end -}}{{- end -}}
{{- $bb := false -}}
{{- range .Columns -}}
{{- $z := .IsQuery -}}
{{- if ($z) -}}
{{- /* "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 -}}
@@ -36,8 +36,7 @@ type {{.ClassName}}GetPageReq struct {
dto.Pagination `search:"-"`
{{- $tablename := .TBName -}}
{{- range .Columns -}}
{{$z := .IsQuery}}
{{- if ($z) }}
{{- 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 }}
+1 -2
View File
@@ -24,8 +24,7 @@ type {{.ClassName}} struct {
// @Tags {{.TableComment}}
{{- $tablename := .TBName -}}
{{- range .Columns -}}
{{$z := .IsQuery}}
{{- if ($z) }}
{{- if eq .IsQuery "1" }}
// @Param {{.JsonField}} query {{.GoType}} false "{{.ColumnComment}}"
{{- end -}}
{{- end }}