Fix filter for task index
This commit is contained in:
parent
ee436efba3
commit
532855d850
2 changed files with 24 additions and 10 deletions
|
@ -985,6 +985,19 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "filter by index",
|
||||||
|
fields: fields{
|
||||||
|
FilterBy: []string{"index"},
|
||||||
|
FilterValue: []string{"5"},
|
||||||
|
FilterComparator: []string{"equals"},
|
||||||
|
},
|
||||||
|
args: defaultArgs,
|
||||||
|
want: []*Task{
|
||||||
|
task5,
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
@ -178,33 +178,34 @@ func (t *Task) ReadAll(s *xorm.Session, a web.Auth, search string, page int, per
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFilterCond(f *taskFilter, includeNulls bool) (cond builder.Cond, err error) {
|
func getFilterCond(f *taskFilter, includeNulls bool) (cond builder.Cond, err error) {
|
||||||
|
field := "`" + f.field + "`"
|
||||||
switch f.comparator {
|
switch f.comparator {
|
||||||
case taskFilterComparatorEquals:
|
case taskFilterComparatorEquals:
|
||||||
cond = &builder.Eq{f.field: f.value}
|
cond = &builder.Eq{field: f.value}
|
||||||
case taskFilterComparatorNotEquals:
|
case taskFilterComparatorNotEquals:
|
||||||
cond = &builder.Neq{f.field: f.value}
|
cond = &builder.Neq{field: f.value}
|
||||||
case taskFilterComparatorGreater:
|
case taskFilterComparatorGreater:
|
||||||
cond = &builder.Gt{f.field: f.value}
|
cond = &builder.Gt{field: f.value}
|
||||||
case taskFilterComparatorGreateEquals:
|
case taskFilterComparatorGreateEquals:
|
||||||
cond = &builder.Gte{f.field: f.value}
|
cond = &builder.Gte{field: f.value}
|
||||||
case taskFilterComparatorLess:
|
case taskFilterComparatorLess:
|
||||||
cond = &builder.Lt{f.field: f.value}
|
cond = &builder.Lt{field: f.value}
|
||||||
case taskFilterComparatorLessEquals:
|
case taskFilterComparatorLessEquals:
|
||||||
cond = &builder.Lte{f.field: f.value}
|
cond = &builder.Lte{field: f.value}
|
||||||
case taskFilterComparatorLike:
|
case taskFilterComparatorLike:
|
||||||
val, is := f.value.(string)
|
val, is := f.value.(string)
|
||||||
if !is {
|
if !is {
|
||||||
return nil, ErrInvalidTaskFilterValue{Field: f.field, Value: f.value}
|
return nil, ErrInvalidTaskFilterValue{Field: field, Value: f.value}
|
||||||
}
|
}
|
||||||
cond = &builder.Like{f.field, "%" + val + "%"}
|
cond = &builder.Like{field, "%" + val + "%"}
|
||||||
case taskFilterComparatorIn:
|
case taskFilterComparatorIn:
|
||||||
cond = builder.In(f.field, f.value)
|
cond = builder.In(field, f.value)
|
||||||
case taskFilterComparatorInvalid:
|
case taskFilterComparatorInvalid:
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
if includeNulls {
|
if includeNulls {
|
||||||
cond = builder.Or(cond, &builder.IsNull{f.field})
|
cond = builder.Or(cond, &builder.IsNull{field})
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue