From 70bcef390f127159617fc5c6b6a68ce89aedfd7b Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 21 Apr 2020 17:31:52 +0200 Subject: [PATCH] Make task sort by string --- pkg/models/error.go | 2 +- pkg/models/task_collection.go | 2 +- pkg/models/task_collection_sort.go | 10 ++-------- pkg/models/task_collection_sort_test.go | 2 +- pkg/models/tasks.go | 6 +++--- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/pkg/models/error.go b/pkg/models/error.go index 3b266af96..952a15eba 100644 --- a/pkg/models/error.go +++ b/pkg/models/error.go @@ -573,7 +573,7 @@ func (err ErrTaskAttachmentIsTooLarge) HTTPError() web.HTTPError { // ErrInvalidSortParam represents an error where the provided sort param is invalid type ErrInvalidSortParam struct { - SortBy sortProperty + SortBy string } // IsErrInvalidSortParam checks if an error is ErrInvalidSortParam. diff --git a/pkg/models/task_collection.go b/pkg/models/task_collection.go index 5907f9e8e..07c991273 100644 --- a/pkg/models/task_collection.go +++ b/pkg/models/task_collection.go @@ -107,7 +107,7 @@ func (tf *TaskCollection) ReadAll(a web.Auth, search string, page int, perPage i var sort = make([]*sortParam, 0, len(tf.SortBy)) for i, s := range tf.SortBy { param := &sortParam{ - sortBy: sortProperty(s), + sortBy: s, orderBy: orderAscending, } // This checks if tf.OrderBy has an entry with the same index as the current entry from tf.SortBy diff --git a/pkg/models/task_collection_sort.go b/pkg/models/task_collection_sort.go index 6a028317a..5413c0d17 100644 --- a/pkg/models/task_collection_sort.go +++ b/pkg/models/task_collection_sort.go @@ -18,12 +18,10 @@ package models type ( sortParam struct { - sortBy sortProperty + sortBy string orderBy sortOrder // asc or desc } - sortProperty string - sortOrder string ) @@ -48,10 +46,6 @@ const ( taskPropertyPosition string = "position" ) -func (p sortProperty) String() string { - return string(p) -} - const ( orderInvalid sortOrder = "invalid" orderAscending sortOrder = "asc" @@ -76,5 +70,5 @@ func (sp *sortParam) validate() error { if sp.orderBy != orderDescending && sp.orderBy != orderAscending { return ErrInvalidSortOrder{OrderBy: sp.orderBy} } - return validateTaskField(string(sp.sortBy)) + return validateTaskField(sp.sortBy) } diff --git a/pkg/models/task_collection_sort_test.go b/pkg/models/task_collection_sort_test.go index 07584863e..606b66647 100644 --- a/pkg/models/task_collection_sort_test.go +++ b/pkg/models/task_collection_sort_test.go @@ -64,7 +64,7 @@ func TestSortParamValidation(t *testing.T) { t.Run(test, func(t *testing.T) { s := &sortParam{ orderBy: orderAscending, - sortBy: sortProperty(test), + sortBy: test, } err := s.validate() assert.NoError(t, err) diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 67e743ae3..ef744477c 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -161,9 +161,9 @@ func getRawTasksForLists(lists []*List, opts *taskOptions) (tasks []*Task, resul // Add the id parameter as the last parameter to sorty by default, but only if it is not already passed as the last parameter. if len(opts.sortby) == 0 || - len(opts.sortby) > 0 && opts.sortby[len(opts.sortby)-1].sortBy != sortProperty(taskPropertyID) { + len(opts.sortby) > 0 && opts.sortby[len(opts.sortby)-1].sortBy != taskPropertyID { opts.sortby = append(opts.sortby, &sortParam{ - sortBy: sortProperty(taskPropertyID), + sortBy: taskPropertyID, orderBy: orderAscending, }) } @@ -177,7 +177,7 @@ func getRawTasksForLists(lists []*List, opts *taskOptions) (tasks []*Task, resul if err := param.validate(); err != nil { return nil, 0, 0, err } - orderby += param.sortBy.String() + " " + param.orderBy.String() + orderby += param.sortBy + " " + param.orderBy.String() if (i + 1) < len(opts.sortby) { orderby += ", " }