Fix task filter
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
94bfcc3b19
commit
a65e2e15b5
|
@ -182,7 +182,7 @@ func TestTaskCollection(t *testing.T) {
|
|||
rec, err := testHandler.testReadAllWithUser(
|
||||
url.Values{
|
||||
"filter_by": []string{"start_date", "end_date", "due_date"},
|
||||
"filter_value": []string{"1544500000", "1544700001", "1543500000"},
|
||||
"filter_value": []string{"1544500000", "2018-12-13T11:20:01+00:00", "1543500000"},
|
||||
"filter_comparator": []string{"greater", "less", "greater"},
|
||||
},
|
||||
urlParams,
|
||||
|
@ -232,7 +232,7 @@ func TestTaskCollection(t *testing.T) {
|
|||
rec, err := testHandler.testReadAllWithUser(
|
||||
url.Values{
|
||||
"filter_by": []string{"end_date"},
|
||||
"filter_value": []string{"1544700001"},
|
||||
"filter_value": []string{"2018-12-13T11:20:01+00:00"},
|
||||
"filter_comparator": []string{"greater"},
|
||||
},
|
||||
urlParams,
|
||||
|
@ -347,7 +347,7 @@ func TestTaskCollection(t *testing.T) {
|
|||
rec, err := testHandler.testReadAllWithUser(
|
||||
url.Values{
|
||||
"filter_by": []string{"start_date", "end_date", "due_date"},
|
||||
"filter_value": []string{"1544500000", "1544700001", "1543500000"},
|
||||
"filter_value": []string{"1544500000", "2018-12-13T11:20:01+00:00", "1543500000"},
|
||||
"filter_comparator": []string{"greater", "less", "greater"},
|
||||
},
|
||||
nil,
|
||||
|
@ -397,7 +397,7 @@ func TestTaskCollection(t *testing.T) {
|
|||
rec, err := testHandler.testReadAllWithUser(
|
||||
url.Values{
|
||||
"filter_by": []string{"end_date"},
|
||||
"filter_value": []string{"1544700001"},
|
||||
"filter_value": []string{"2018-12-13T11:20:01+00:00"},
|
||||
"filter_comparator": []string{"greater"},
|
||||
},
|
||||
nil,
|
||||
|
|
|
@ -18,9 +18,13 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"fmt"
|
||||
"github.com/iancoleman/strcase"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
type taskFilterComparator string
|
||||
|
@ -144,7 +148,13 @@ func getNativeValueForTaskField(fieldName, value string) (nativeValue interface{
|
|||
nativeValue = value
|
||||
case reflect.Bool:
|
||||
nativeValue, err = strconv.ParseBool(value)
|
||||
case reflect.Struct:
|
||||
if field.Type == schemas.TimeType {
|
||||
nativeValue, err = time.Parse(time.RFC3339, value)
|
||||
nativeValue = nativeValue.(time.Time).In(config.GetTimeZone())
|
||||
}
|
||||
default:
|
||||
panic(fmt.Errorf("unrecognized filter type %s for field %s, value %s", field.Type.String(), fieldName, value))
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
@ -673,7 +673,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
|||
name: "ReadAll Tasks with range",
|
||||
fields: fields{
|
||||
FilterBy: []string{"start_date", "end_date"},
|
||||
FilterValue: []string{"1544500000", "1544700001"},
|
||||
FilterValue: []string{"2018-12-11T03:46:40+00:00", "2018-12-13T11:20:01+00:00"},
|
||||
FilterComparator: []string{"greater", "less"},
|
||||
},
|
||||
args: defaultArgs,
|
||||
|
@ -688,7 +688,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
|||
name: "ReadAll Tasks with different range",
|
||||
fields: fields{
|
||||
FilterBy: []string{"start_date", "end_date"},
|
||||
FilterValue: []string{"1544700000", "1545000000"},
|
||||
FilterValue: []string{"2018-12-13T11:20:00+00:00", "2018-12-16T22:40:00+00:00"},
|
||||
FilterComparator: []string{"greater", "less"},
|
||||
},
|
||||
args: defaultArgs,
|
||||
|
@ -702,7 +702,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
|||
name: "ReadAll Tasks with range with start date only",
|
||||
fields: fields{
|
||||
FilterBy: []string{"start_date"},
|
||||
FilterValue: []string{"1544600000"},
|
||||
FilterValue: []string{"2018-12-12T07:33:20+00:00"},
|
||||
FilterComparator: []string{"greater"},
|
||||
},
|
||||
args: defaultArgs,
|
||||
|
@ -713,7 +713,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
|||
name: "ReadAll Tasks with range with start date only and greater equals",
|
||||
fields: fields{
|
||||
FilterBy: []string{"start_date"},
|
||||
FilterValue: []string{"1544600000"},
|
||||
FilterValue: []string{"2018-12-12T07:33:20+00:00"},
|
||||
FilterComparator: []string{"greater_equals"},
|
||||
},
|
||||
args: defaultArgs,
|
||||
|
|
Loading…
Reference in New Issue