mirror of
https://github.com/owncloud/ocis
synced 2026-04-25 17:25:21 +02:00
Simplify sort code a bit
Switch to sort.Slice() instead of sort.Sort(), which requires less boilerplate.
This commit is contained in:
committed by
Ralf Haferkamp
parent
1ed52fb57f
commit
4717248959
@@ -404,20 +404,25 @@ func (g Graph) DeleteGroupMember(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func sortGroups(req *godata.GoDataRequest, groups []*libregraph.Group) ([]*libregraph.Group, error) {
|
||||
var sorter sort.Interface
|
||||
if req.Query.OrderBy == nil || len(req.Query.OrderBy.OrderByItems) != 1 {
|
||||
return groups, nil
|
||||
}
|
||||
var less func(i, j int) bool
|
||||
|
||||
switch req.Query.OrderBy.OrderByItems[0].Field.Value {
|
||||
case displayNameAttr:
|
||||
sorter = groupsByDisplayName{groups}
|
||||
less = func(i, j int) bool {
|
||||
return strings.ToLower(groups[i].GetDisplayName()) < strings.ToLower(groups[j].GetDisplayName())
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("we do not support <%s> as a order parameter", req.Query.OrderBy.OrderByItems[0].Field.Value)
|
||||
}
|
||||
|
||||
if req.Query.OrderBy.OrderByItems[0].Order == _sortDescending {
|
||||
sorter = sort.Reverse(sorter)
|
||||
sort.Slice(groups, reverse(less))
|
||||
} else {
|
||||
sort.Slice(groups, less)
|
||||
}
|
||||
sort.Sort(sorter)
|
||||
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user