Skip to content

Commit cdff350

Browse files
committed
Allow dumb filters without exceptions
Maybe reintroduce later with a super strict mode, but this is just unnecessary for the time being.
1 parent 1177ce5 commit cdff350

File tree

5 files changed

+11
-238
lines changed

5 files changed

+11
-238
lines changed

attributes/a_bool_filters.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ func (b Bool) AvailableFilters() []interface{} {
7676
func (b Bool) ValidateFilters(queries map[string][]string) ([]schema.Filter, error) {
7777
valids := []schema.Filter{}
7878

79-
// null check
80-
nullsOnly := false
81-
nonNullsOnly := false
82-
8379
nullKey := b.Key + filters.ISNULL_SUFFIX
8480
nullStrings, exists := queries[nullKey]
8581
if exists {
@@ -91,7 +87,6 @@ func (b Bool) ValidateFilters(queries map[string][]string) ([]schema.Filter, err
9187
}
9288
isNullString := strings.ToLower(nullStrings[0])
9389
if isNullString == "true" {
94-
nullsOnly = true
9590
valids = append(valids, BoolNullFilter{
9691
BaseFilter: &schema.BaseFilter{
9792
QArgKey: nullKey,
@@ -101,8 +96,6 @@ func (b Bool) ValidateFilters(queries map[string][]string) ([]schema.Filter, err
10196
column: b.ColumnName,
10297
})
10398
} else if isNullString == "false" {
104-
nonNullsOnly = true
105-
_ = nonNullsOnly
10699
valids = append(valids, BoolNullFilter{
107100
BaseFilter: &schema.BaseFilter{
108101
QArgKey: nullKey,
@@ -129,13 +122,6 @@ func (b Bool) ValidateFilters(queries map[string][]string) ([]schema.Filter, err
129122
)
130123
}
131124

132-
if nullsOnly {
133-
return filters.Exception(
134-
"Cannot match attribute '%s' to an exact value and null.",
135-
b.Key,
136-
)
137-
}
138-
139125
compareValue := strings.ToLower(exactStrings[0])
140126
if compareValue == "true" {
141127
valids = append(valids, BoolExactFilter{

attributes/a_date_filters.go

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ func (d Date) AvailableFilters() []interface{} {
125125
func (d Date) ValidateFilters(queries map[string][]string) ([]schema.Filter, error) {
126126
valids := []schema.Filter{}
127127

128-
// null check
129-
nullsOnly := false
130-
nonNullsOnly := false
131-
132128
nullKey := d.Key + filters.ISNULL_SUFFIX
133129
nullStrings, exists := queries[nullKey]
134130
if exists {
@@ -140,7 +136,6 @@ func (d Date) ValidateFilters(queries map[string][]string) ([]schema.Filter, err
140136
}
141137
isNullString := strings.ToLower(nullStrings[0])
142138
if isNullString == "true" {
143-
nullsOnly = true
144139
valids = append(valids, DateNullFilter{
145140
BaseFilter: &schema.BaseFilter{
146141
QArgKey: nullKey,
@@ -150,8 +145,6 @@ func (d Date) ValidateFilters(queries map[string][]string) ([]schema.Filter, err
150145
column: d.ColumnName,
151146
})
152147
} else if isNullString == "false" {
153-
nonNullsOnly = true
154-
_ = nonNullsOnly
155148
valids = append(valids, DateNullFilter{
156149
BaseFilter: &schema.BaseFilter{
157150
QArgKey: nullKey,
@@ -178,13 +171,6 @@ func (d Date) ValidateFilters(queries map[string][]string) ([]schema.Filter, err
178171
)
179172
}
180173

181-
if nullsOnly {
182-
return filters.Exception(
183-
"Cannot match attribute '%s' to an exact value and null.",
184-
d.Key,
185-
)
186-
}
187-
188174
compareValue, err := time.Parse(DATE_LAYOUT, exactStrings[0])
189175
if err == nil {
190176
valids = append(valids, DateExactFilter{
@@ -204,9 +190,6 @@ func (d Date) ValidateFilters(queries map[string][]string) ([]schema.Filter, err
204190
}
205191
}
206192

207-
filteringAfter := false
208-
var filteringAfterValue time.Time
209-
210193
afterKey := d.Key + filters.AFTER_SUFFIX
211194
afterStrings, exists := queries[afterKey]
212195
if exists {
@@ -217,18 +200,8 @@ func (d Date) ValidateFilters(queries map[string][]string) ([]schema.Filter, err
217200
)
218201
}
219202

220-
if nullsOnly {
221-
return filters.Exception(
222-
"Cannot compare attribute '%s' to a value and null.",
223-
d.Key,
224-
)
225-
}
226-
227203
afterValue, err := time.Parse(DATE_LAYOUT, afterStrings[0])
228204
if err == nil {
229-
filteringAfter = true
230-
filteringAfterValue = afterValue
231-
232205
valids = append(valids, DateAfterFilter{
233206
BaseFilter: &schema.BaseFilter{
234207
QArgKey: afterKey,
@@ -257,38 +230,23 @@ func (d Date) ValidateFilters(queries map[string][]string) ([]schema.Filter, err
257230
)
258231
}
259232

260-
if nullsOnly {
261-
return filters.Exception(
262-
"Cannot compare attribute '%s' to a value and null.",
263-
d.Key,
264-
)
265-
}
266-
267233
beforeValue, err := time.Parse(DATE_LAYOUT, beforeStrings[0])
268-
if err == nil {
269-
if filteringAfter && beforeValue.Before(filteringAfterValue) {
270-
return filters.Exception(
271-
"Cannot compare attribute '%s' to value before additional after filter.",
272-
d.Key,
273-
)
274-
}
275-
276-
valids = append(valids, DateAfterFilter{
277-
BaseFilter: &schema.BaseFilter{
278-
QArgKey: beforeKey,
279-
QArgValues: []string{beforeValue.Format(DATE_LAYOUT)},
280-
},
281-
value: beforeValue,
282-
column: d.ColumnName,
283-
after: false,
284-
})
285-
} else {
234+
if err != nil {
286235
return filters.Exception(
287236
"Invalid before comparison value on attribute '%s'. Must be date in format %s.",
288237
d.Key,
289238
DATE_LAYOUT,
290239
)
291240
}
241+
valids = append(valids, DateAfterFilter{
242+
BaseFilter: &schema.BaseFilter{
243+
QArgKey: beforeKey,
244+
QArgValues: []string{beforeValue.Format(DATE_LAYOUT)},
245+
},
246+
value: beforeValue,
247+
column: d.ColumnName,
248+
after: false,
249+
})
292250
}
293251

294252
return valids, nil

attributes/a_datetime_filters.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ func (dt Datetime) AvailableFilters() []interface{} {
129129
func (dt Datetime) ValidateFilters(queries map[string][]string) ([]schema.Filter, error) {
130130
valids := []schema.Filter{}
131131

132-
// null check
133-
nullsOnly := false
134-
nonNullsOnly := false
135-
136132
nullKey := dt.Key + filters.ISNULL_SUFFIX
137133
nullStrings, exists := queries[nullKey]
138134
if exists {
@@ -144,7 +140,6 @@ func (dt Datetime) ValidateFilters(queries map[string][]string) ([]schema.Filter
144140
}
145141
isNullString := strings.ToLower(nullStrings[0])
146142
if isNullString == "true" {
147-
nullsOnly = true
148143
valids = append(valids, DatetimeNullFilter{
149144
BaseFilter: &schema.BaseFilter{
150145
QArgKey: nullKey,
@@ -154,8 +149,6 @@ func (dt Datetime) ValidateFilters(queries map[string][]string) ([]schema.Filter
154149
column: dt.ColumnName,
155150
})
156151
} else if isNullString == "false" {
157-
nonNullsOnly = true
158-
_ = nonNullsOnly
159152
valids = append(valids, DatetimeNullFilter{
160153
BaseFilter: &schema.BaseFilter{
161154
QArgKey: nullKey,
@@ -182,13 +175,6 @@ func (dt Datetime) ValidateFilters(queries map[string][]string) ([]schema.Filter
182175
)
183176
}
184177

185-
if nullsOnly {
186-
return filters.Exception(
187-
"Cannot match attribute '%s' to an exact value and null.",
188-
dt.Key,
189-
)
190-
}
191-
192178
compareValue, err := time.Parse(time.RFC3339, exactStrings[0])
193179
if err == nil {
194180
valids = append(valids, DatetimeExactFilter{
@@ -207,9 +193,6 @@ func (dt Datetime) ValidateFilters(queries map[string][]string) ([]schema.Filter
207193
}
208194
}
209195

210-
filteringAfter := false
211-
var filteringAfterValue time.Time
212-
213196
afterKey := dt.Key + filters.AFTER_SUFFIX
214197
afterStrings, exists := queries[afterKey]
215198
if exists {
@@ -220,18 +203,8 @@ func (dt Datetime) ValidateFilters(queries map[string][]string) ([]schema.Filter
220203
)
221204
}
222205

223-
if nullsOnly {
224-
return filters.Exception(
225-
"Cannot compare attribute '%s' to a value and null.",
226-
dt.Key,
227-
)
228-
}
229-
230206
afterValue, err := time.Parse(time.RFC3339, afterStrings[0])
231207
if err == nil {
232-
filteringAfter = true
233-
filteringAfterValue = afterValue
234-
235208
valids = append(valids, DatetimeAfterFilter{
236209
BaseFilter: &schema.BaseFilter{
237210
QArgKey: afterKey,
@@ -259,22 +232,8 @@ func (dt Datetime) ValidateFilters(queries map[string][]string) ([]schema.Filter
259232
)
260233
}
261234

262-
if nullsOnly {
263-
return filters.Exception(
264-
"Cannot compare attribute '%s' to a value and null.",
265-
dt.Key,
266-
)
267-
}
268-
269235
beforeValue, err := time.Parse(time.RFC3339, beforeStrings[0])
270236
if err == nil {
271-
if filteringAfter && beforeValue.Before(filteringAfterValue) {
272-
return filters.Exception(
273-
"Cannot compare attribute '%s' to value before additional after filter.",
274-
dt.Key,
275-
)
276-
}
277-
278237
valids = append(valids, DatetimeAfterFilter{
279238
BaseFilter: &schema.BaseFilter{
280239
QArgKey: beforeKey,

attributes/a_integer_filters.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ func (i Integer) AvailableFilters() []interface{} {
116116
func (i Integer) ValidateFilters(queries map[string][]string) ([]schema.Filter, error) {
117117
valids := []schema.Filter{}
118118

119-
// null check
120-
nullsOnly := false
121-
nonNullsOnly := false
122-
123119
nullKey := i.Key + filters.ISNULL_SUFFIX
124120
nullStrings, exists := queries[nullKey]
125121
if exists {
@@ -131,7 +127,6 @@ func (i Integer) ValidateFilters(queries map[string][]string) ([]schema.Filter,
131127
}
132128
isNullString := strings.ToLower(nullStrings[0])
133129
if isNullString == "true" {
134-
nullsOnly = true
135130
valids = append(valids, IntegerNullFilter{
136131
BaseFilter: &schema.BaseFilter{
137132
QArgKey: nullKey,
@@ -141,8 +136,6 @@ func (i Integer) ValidateFilters(queries map[string][]string) ([]schema.Filter,
141136
column: i.ColumnName,
142137
})
143138
} else if isNullString == "false" {
144-
nonNullsOnly = true
145-
_ = nonNullsOnly
146139
valids = append(valids, IntegerNullFilter{
147140
BaseFilter: &schema.BaseFilter{
148141
QArgKey: nullKey,
@@ -169,13 +162,6 @@ func (i Integer) ValidateFilters(queries map[string][]string) ([]schema.Filter,
169162
)
170163
}
171164

172-
if nullsOnly {
173-
return filters.Exception(
174-
"Cannot match attribute '%s' to an exact value and null.",
175-
i.Key,
176-
)
177-
}
178-
179165
compareValue, err := strconv.Atoi(exactStrings[0])
180166
if err == nil {
181167
valids = append(valids, IntegerExactFilter{
@@ -194,9 +180,6 @@ func (i Integer) ValidateFilters(queries map[string][]string) ([]schema.Filter,
194180
}
195181
}
196182

197-
filteringLesser := false
198-
var filteringLesserValue int
199-
200183
lesserKey := i.Key + filters.LT_SUFFIX
201184
lesserStrings, exists := queries[lesserKey]
202185
if exists {
@@ -207,18 +190,8 @@ func (i Integer) ValidateFilters(queries map[string][]string) ([]schema.Filter,
207190
)
208191
}
209192

210-
if nullsOnly {
211-
return filters.Exception(
212-
"Cannot compare attribute '%s' to a value and null.",
213-
i.Key,
214-
)
215-
}
216-
217193
lesserValue, err := strconv.Atoi(lesserStrings[0])
218194
if err == nil {
219-
filteringLesser = true
220-
filteringLesserValue = lesserValue
221-
222195
valids = append(valids, IntegerLesserFilter{
223196
BaseFilter: &schema.BaseFilter{
224197
QArgKey: lesserKey,
@@ -246,22 +219,8 @@ func (i Integer) ValidateFilters(queries map[string][]string) ([]schema.Filter,
246219
)
247220
}
248221

249-
if nullsOnly {
250-
return filters.Exception(
251-
"Cannot compare attribute '%s' to a value and null.",
252-
i.Key,
253-
)
254-
}
255-
256222
greaterValue, err := strconv.Atoi(greaterStrings[0])
257223
if err == nil {
258-
if filteringLesser && greaterValue > filteringLesserValue {
259-
return filters.Exception(
260-
"Cannot compare attribute '%s' to value greater than additional lesser than filter.",
261-
i.Key,
262-
)
263-
}
264-
265224
valids = append(valids, IntegerLesserFilter{
266225
BaseFilter: &schema.BaseFilter{
267226
QArgKey: greaterKey,

0 commit comments

Comments
 (0)