Make task sort by string
continuous-integration/drone/pr Build was killed Details

This commit is contained in:
kolaente 2020-04-21 17:31:52 +02:00
parent f4d1042eb9
commit 70bcef390f
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
5 changed files with 8 additions and 14 deletions

View File

@ -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.

View File

@ -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

View File

@ -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)
}

View File

@ -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)

View File

@ -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 += ", "
}