Make task sort by string
continuous-integration/drone/pr Build was killed
Details
continuous-integration/drone/pr Build was killed
Details
This commit is contained in:
parent
f4d1042eb9
commit
70bcef390f
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 += ", "
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue