From d483fe8bebc98c09141dca4977cdfb3c63a64a9b Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 7 Dec 2019 16:57:19 +0100 Subject: [PATCH] Fix passing sort_by and order_by as query path arrays --- pkg/models/task_collection.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/models/task_collection.go b/pkg/models/task_collection.go index 16cc1062e03..3bd26b8568d 100644 --- a/pkg/models/task_collection.go +++ b/pkg/models/task_collection.go @@ -30,9 +30,11 @@ type TaskCollection struct { Lists []*List // The query parameter to sort by. This is for ex. done, priority, etc. - SortBy []string `query:"sort_by"` + SortBy []string `query:"sort_by"` + SortByArr []string `query:"sort_by[]"` // The query parameter to order the items by. This can be either asc or desc, with asc being the default. - OrderBy []string `query:"order_by"` + OrderBy []string `query:"order_by"` + OrderByArr []string `query:"order_by[]"` web.CRUDable `xorm:"-" json:"-"` web.Rights `xorm:"-" json:"-"` @@ -58,6 +60,14 @@ type TaskCollection struct { // @Router /lists/{listID}/tasks [get] func (tf *TaskCollection) ReadAll(a web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, totalItems int64, err error) { + if len(tf.SortByArr) > 0 { + tf.SortBy = append(tf.SortBy, tf.SortByArr...) + } + + if len(tf.OrderByArr) > 0 { + tf.OrderBy = append(tf.OrderBy, tf.OrderByArr...) + } + var sort = make([]*sortParam, 0, len(tf.SortBy)) for i, s := range tf.SortBy { param := &sortParam{