diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index c2abdc436..0c1fda57c 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -791,7 +791,7 @@ func sortSpaces(req *godata.GoDataRequest, spaces []*libregraph.Drive) ([]*libre 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 == "asc" { + if req.Query.OrderBy.OrderByItems[0].Order == "desc" { sorter = sort.Reverse(sorter) } sort.Sort(sorter) diff --git a/graph/pkg/service/v0/groups.go b/graph/pkg/service/v0/groups.go index 8c76c5c18..0baa90759 100644 --- a/graph/pkg/service/v0/groups.go +++ b/graph/pkg/service/v0/groups.go @@ -352,7 +352,7 @@ func sortGroups(req *godata.GoDataRequest, groups []*libregraph.Group) ([]*libre 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 == "asc" { + if req.Query.OrderBy.OrderByItems[0].Order == "desc" { sorter = sort.Reverse(sorter) } sort.Sort(sorter) diff --git a/graph/pkg/service/v0/ordering.go b/graph/pkg/service/v0/ordering.go index 0655af011..117356a4f 100644 --- a/graph/pkg/service/v0/ordering.go +++ b/graph/pkg/service/v0/ordering.go @@ -24,7 +24,7 @@ type spacesByLastModifiedDateTime struct { // Less reports whether the element with index i // must sort before the element with index j. func (s spacesByName) Less(i, j int) bool { - return strings.ToLower(*s.spacesSlice[i].Name) > strings.ToLower(*s.spacesSlice[j].Name) + return strings.ToLower(*s.spacesSlice[i].Name) < strings.ToLower(*s.spacesSlice[j].Name) } // Less reports whether the element with index i @@ -32,18 +32,18 @@ func (s spacesByName) Less(i, j int) bool { func (s spacesByLastModifiedDateTime) Less(i, j int) bool { // compare the items when both dates are set if s.spacesSlice[i].LastModifiedDateTime != nil && s.spacesSlice[j].LastModifiedDateTime != nil { - return s.spacesSlice[i].LastModifiedDateTime.After(*s.spacesSlice[j].LastModifiedDateTime) + return s.spacesSlice[i].LastModifiedDateTime.Before(*s.spacesSlice[j].LastModifiedDateTime) } - // move left item down if it has no value + // an item without a timestamp is considered "less than" an item with a timestamp if s.spacesSlice[i].LastModifiedDateTime == nil && s.spacesSlice[j].LastModifiedDateTime != nil { - return false - } - // move right item down if it has no value - if s.spacesSlice[i].LastModifiedDateTime != nil && s.spacesSlice[j].LastModifiedDateTime == nil { return true } + // an item without a timestamp is considered "less than" an item with a timestamp + if s.spacesSlice[i].LastModifiedDateTime != nil && s.spacesSlice[j].LastModifiedDateTime == nil { + return false + } // fallback to name if no dateTime is set on both items - return strings.ToLower(*s.spacesSlice[i].Name) > strings.ToLower(*s.spacesSlice[j].Name) + return strings.ToLower(*s.spacesSlice[i].Name) < strings.ToLower(*s.spacesSlice[j].Name) } type userSlice []*libregraph.User @@ -69,19 +69,19 @@ type usersByOnPremisesSamAccountName struct { // Less reports whether the element with index i // must sort before the element with index j. func (u usersByDisplayName) Less(i, j int) bool { - return strings.ToLower(u.userSlice[i].GetDisplayName()) > strings.ToLower(u.userSlice[j].GetDisplayName()) + return strings.ToLower(u.userSlice[i].GetDisplayName()) < strings.ToLower(u.userSlice[j].GetDisplayName()) } // Less reports whether the element with index i // must sort before the element with index j. func (u usersByMail) Less(i, j int) bool { - return strings.ToLower(u.userSlice[i].GetMail()) > strings.ToLower(u.userSlice[j].GetMail()) + return strings.ToLower(u.userSlice[i].GetMail()) < strings.ToLower(u.userSlice[j].GetMail()) } // Less reports whether the element with index i // must sort before the element with index j. func (u usersByOnPremisesSamAccountName) Less(i, j int) bool { - return strings.ToLower(u.userSlice[i].GetOnPremisesSamAccountName()) > strings.ToLower(u.userSlice[j].GetOnPremisesSamAccountName()) + return strings.ToLower(u.userSlice[i].GetOnPremisesSamAccountName()) < strings.ToLower(u.userSlice[j].GetOnPremisesSamAccountName()) } type groupSlice []*libregraph.Group @@ -99,5 +99,5 @@ type groupsByDisplayName struct { // Less reports whether the element with index i // must sort before the element with index j. func (g groupsByDisplayName) Less(i, j int) bool { - return strings.ToLower(g.groupSlice[i].GetDisplayName()) > strings.ToLower(g.groupSlice[j].GetDisplayName()) + return strings.ToLower(g.groupSlice[i].GetDisplayName()) < strings.ToLower(g.groupSlice[j].GetDisplayName()) } diff --git a/graph/pkg/service/v0/users.go b/graph/pkg/service/v0/users.go index 7495a2f54..0cc29954f 100644 --- a/graph/pkg/service/v0/users.go +++ b/graph/pkg/service/v0/users.go @@ -272,7 +272,7 @@ func sortUsers(req *godata.GoDataRequest, users []*libregraph.User) ([]*libregra 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 == "asc" { + if req.Query.OrderBy.OrderByItems[0].Order == "desc" { sorter = sort.Reverse(sorter) } sort.Sort(sorter)