Skip to content

Commit

Permalink
order by name if no date is set
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Feb 20, 2022
1 parent e589286 commit 67c0eb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions graph/pkg/service/v0/drives.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ func (g Graph) sortSpaces(req *godata.GoDataRequest, spaces []*libregraph.Drive)
if spaces[p].LastModifiedDateTime != nil && spaces[q].LastModifiedDateTime == nil {
return true
}
return false
// fallback to name if no dateTime is set on both items
return *spaces[p].Name > *spaces[q].Name
},
)
}
Expand All @@ -767,7 +768,8 @@ func (g Graph) sortSpaces(req *godata.GoDataRequest, spaces []*libregraph.Drive)
if spaces[p].LastModifiedDateTime != nil && spaces[q].LastModifiedDateTime == nil {
return false
}
return true
// fallback to name if no dateTime is set on both items
return *spaces[p].Name < *spaces[q].Name
},
)
}
Expand Down
16 changes: 12 additions & 4 deletions graph/pkg/service/v0/drives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ type sortTest struct {

var Time1 = time.Date(2022, 02, 02, 15, 00, 00, 00, time.UTC)
var Time2 = time.Date(2022, 02, 03, 15, 00, 00, 00, time.UTC)
var Time3 *time.Time
var Time3, Time5, Time6 *time.Time
var Time4 = time.Date(2022, 02, 05, 15, 00, 00, 00, time.UTC)
var Drives = []*libregraph.Drive{
{Id: libregraph.PtrString("3"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Admin"), LastModifiedDateTime: Time3},
{Id: libregraph.PtrString("1"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Einstein"), LastModifiedDateTime: &Time1},
{Id: libregraph.PtrString("2"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Marie"), LastModifiedDateTime: &Time2},
{Id: libregraph.PtrString("3"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Admin"), LastModifiedDateTime: Time3},
{Id: libregraph.PtrString("4"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Richard"), LastModifiedDateTime: &Time4},
}
var DrivesLong = append(Drives, []*libregraph.Drive{
{Id: libregraph.PtrString("5"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Bob"), LastModifiedDateTime: Time5},
{Id: libregraph.PtrString("6"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Alice"), LastModifiedDateTime: Time6},
}...)

var sortTests = []sortTest{
{
Expand Down Expand Up @@ -64,7 +68,7 @@ var sortTests = []sortTest{
},
},
{
Drives: Drives,
Drives: DrivesLong,
Query: godata.GoDataRequest{
Query: &godata.GoDataQuery{
OrderBy: &godata.GoDataOrderByQuery{
Expand All @@ -76,13 +80,15 @@ var sortTests = []sortTest{
},
DrivesSorted: []*libregraph.Drive{
{Id: libregraph.PtrString("3"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Admin"), LastModifiedDateTime: Time3},
{Id: libregraph.PtrString("6"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Alice"), LastModifiedDateTime: Time6},
{Id: libregraph.PtrString("5"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Bob"), LastModifiedDateTime: Time5},
{Id: libregraph.PtrString("1"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Einstein"), LastModifiedDateTime: &Time1},
{Id: libregraph.PtrString("2"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Marie"), LastModifiedDateTime: &Time2},
{Id: libregraph.PtrString("4"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Richard"), LastModifiedDateTime: &Time4},
},
},
{
Drives: Drives,
Drives: DrivesLong,
Query: godata.GoDataRequest{
Query: &godata.GoDataQuery{
OrderBy: &godata.GoDataOrderByQuery{
Expand All @@ -96,6 +102,8 @@ var sortTests = []sortTest{
{Id: libregraph.PtrString("4"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Richard"), LastModifiedDateTime: &Time4},
{Id: libregraph.PtrString("2"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Marie"), LastModifiedDateTime: &Time2},
{Id: libregraph.PtrString("1"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Einstein"), LastModifiedDateTime: &Time1},
{Id: libregraph.PtrString("5"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Bob"), LastModifiedDateTime: Time5},
{Id: libregraph.PtrString("6"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Alice"), LastModifiedDateTime: Time6},
{Id: libregraph.PtrString("3"), DriveType: libregraph.PtrString("project"), Name: libregraph.PtrString("Admin"), LastModifiedDateTime: Time3},
},
},
Expand Down

0 comments on commit 67c0eb4

Please sign in to comment.