Fix RDBMS filter construction for applications and flags
* Add a new byFlag resource filter feature to support filtering using flags. False by default since only system applications use it. * Add filter definitions to flag pkg resource. * Add support for using []string inside byValue filters.
This commit is contained in:
@@ -52,6 +52,10 @@ func {{ .expIdent }}Filter(f {{ .goFilterType }})(ee []goqu.Expression, _ {{ .go
|
||||
if val := strings.TrimSpace(f.{{ .expIdent }}); len(val) > 0 {
|
||||
ee = append(ee, goqu.C({{ printf "%q" .storeIdent }}).Eq(f.{{ .expIdent }}))
|
||||
}
|
||||
{{ else if eq .goType "[]string" }}
|
||||
if ss := trimStringSlice(f.{{ .expIdent }}); len(ss) > 0 {
|
||||
ee = append(ee, goqu.C({{ printf "%q" .storeIdent }}).In(ss))
|
||||
}
|
||||
{{ else if eq .goType "bool" }}
|
||||
if f.{{ .expIdent }} {
|
||||
ee = append(ee, goqu.C({{ printf "%q" .storeIdent }}).IsTrue())
|
||||
@@ -76,6 +80,12 @@ func {{ .expIdent }}Filter(f {{ .goFilterType }})(ee []goqu.Expression, _ {{ .go
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if .filter.byFlag }}
|
||||
if len(f.FlaggedIDs) > 0 {
|
||||
ee = append(ee, goqu.I("id").In(f.FlaggedIDs))
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if .filter.query }}
|
||||
if f.Query != "" {
|
||||
ee = append(ee, goqu.Or(
|
||||
@@ -89,3 +99,14 @@ func {{ .expIdent }}Filter(f {{ .goFilterType }})(ee []goqu.Expression, _ {{ .go
|
||||
return ee, f, err
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
// trimStringSlice is a utility to trim all of the string slice elements and omit empty ones
|
||||
func trimStringSlice(in []string) []string {
|
||||
out := make([]string, 0, len(in))
|
||||
for _, s := range in {
|
||||
if t := strings.TrimSpace(s); len(t) > 0 {
|
||||
out = append(out, t)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -42,6 +42,9 @@ import (
|
||||
// filtering by label
|
||||
labels: bool | *true
|
||||
|
||||
// filtering by flag
|
||||
flags: bool | *false
|
||||
|
||||
// support pagination
|
||||
paging: bool | *true
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ _StoreResource: {
|
||||
// @todo this should be pulled from the struct
|
||||
"byValue": [ for name in res.filter.byValue {res.filter.struct[name]}]
|
||||
"byLabel": res.features.labels
|
||||
"byFlag": res.features.flags
|
||||
}
|
||||
|
||||
auxIdent: "aux\(expIdent)"
|
||||
|
||||
Reference in New Issue
Block a user