From c58fed9e22bd32d3eb1ebbdadf18ffe46ffaa524 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Tue, 22 Feb 2022 20:45:44 +0100 Subject: [PATCH] fix ordering of names (#3218) --- changelog/unreleased/add-ordering-list-drives.md | 1 + graph/pkg/service/v0/drives_test.go | 12 ++++++------ graph/pkg/service/v0/ordering.go | 6 ++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/changelog/unreleased/add-ordering-list-drives.md b/changelog/unreleased/add-ordering-list-drives.md index 7ec005ee2..21f451071 100644 --- a/changelog/unreleased/add-ordering-list-drives.md +++ b/changelog/unreleased/add-ordering-list-drives.md @@ -7,3 +7,4 @@ Example 2: https://localhost:9200/graph/v1.0/me/drives/?$orderby=name asc https://github.com/owncloud/ocis/issues/3200 https://github.com/owncloud/ocis/pull/3201 +https://github.com/owncloud/ocis/pull/3218 diff --git a/graph/pkg/service/v0/drives_test.go b/graph/pkg/service/v0/drives_test.go index 036ca90f5..954b24c4c 100644 --- a/graph/pkg/service/v0/drives_test.go +++ b/graph/pkg/service/v0/drives_test.go @@ -26,8 +26,8 @@ var drives = []*libregraph.Drive{ drive("4", "project", "Richard", &time4), } var drivesLong = append(drives, []*libregraph.Drive{ - drive("5", "project", "Bob", time5), - drive("6", "project", "Alice", time6), + drive("5", "project", "bob", time5), + drive("6", "project", "alice", time6), }...) var sortTests = []sortTest{ @@ -80,8 +80,8 @@ var sortTests = []sortTest{ }, DrivesSorted: []*libregraph.Drive{ drive("3", "project", "Admin", time3), - drive("6", "project", "Alice", time6), - drive("5", "project", "Bob", time5), + drive("6", "project", "alice", time6), + drive("5", "project", "bob", time5), drive("1", "project", "Einstein", &time1), drive("2", "project", "Marie", &time2), drive("4", "project", "Richard", &time4), @@ -102,8 +102,8 @@ var sortTests = []sortTest{ drive("4", "project", "Richard", &time4), drive("2", "project", "Marie", &time2), drive("1", "project", "Einstein", &time1), - drive("5", "project", "Bob", time5), - drive("6", "project", "Alice", time6), + drive("5", "project", "bob", time5), + drive("6", "project", "alice", time6), drive("3", "project", "Admin", time3), }, }, diff --git a/graph/pkg/service/v0/ordering.go b/graph/pkg/service/v0/ordering.go index 7749cafb0..4dd0f4a54 100644 --- a/graph/pkg/service/v0/ordering.go +++ b/graph/pkg/service/v0/ordering.go @@ -1,6 +1,8 @@ package svc import ( + "strings" + libregraph "github.com/owncloud/libre-graph-api-go" ) @@ -22,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 *s.spacesSlice[i].Name > *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 @@ -41,5 +43,5 @@ func (s spacesByLastModifiedDateTime) Less(i, j int) bool { return true } // fallback to name if no dateTime is set on both items - return *s.spacesSlice[i].Name > *s.spacesSlice[j].Name + return strings.ToLower(*s.spacesSlice[i].Name) > strings.ToLower(*s.spacesSlice[j].Name) }