From 2834a83a27d4e4e64d90c4bde4a5c1ce15446f7a Mon Sep 17 00:00:00 2001 From: griffri Date: Fri, 11 Oct 2024 15:50:43 +0100 Subject: [PATCH 1/2] Return specified field for `orderByDescending=` query --- .../API/Features/Storage/StorageController.cs | 8 ++++++-- .../API/Infrastructure/ControllerBaseX.cs | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/IIIFPresentation/API/Features/Storage/StorageController.cs b/src/IIIFPresentation/API/Features/Storage/StorageController.cs index 7348f1a..4d40a72 100644 --- a/src/IIIFPresentation/API/Features/Storage/StorageController.cs +++ b/src/IIIFPresentation/API/Features/Storage/StorageController.cs @@ -71,14 +71,18 @@ public async Task Get(int customerId, string id, int? page = 1, i var orderByField = this.GetOrderBy(orderBy, orderByDescending, out var descending); var storageRoot = - await Mediator.Send(new GetCollection(customerId, id, page.Value, pageSize.Value, orderBy, descending)); + await Mediator.Send(new GetCollection(customerId, id, page.Value, pageSize.Value, orderByField, descending)); if (storageRoot.Collection == null) return this.PresentationNotFound(); if (Request.ShowExtraProperties()) { + var orderByParameter = orderByField != null + ? $"{(descending ? nameof(orderByDescending) : nameof(orderBy))}={orderByField}" + : null; + return Ok(storageRoot.Collection.ToFlatCollection(GetUrlRoots(), pageSize.Value, page.Value, - storageRoot.TotalItems, storageRoot.Items, orderByField)); + storageRoot.TotalItems, storageRoot.Items, orderByParameter)); } return SeeOther(storageRoot.Collection.GenerateHierarchicalCollectionId(GetUrlRoots())); diff --git a/src/IIIFPresentation/API/Infrastructure/ControllerBaseX.cs b/src/IIIFPresentation/API/Infrastructure/ControllerBaseX.cs index 63c1c87..497578a 100644 --- a/src/IIIFPresentation/API/Infrastructure/ControllerBaseX.cs +++ b/src/IIIFPresentation/API/Infrastructure/ControllerBaseX.cs @@ -102,11 +102,11 @@ public static ObjectResult ValidationFailed(this ControllerBase controller, Vali descending = false; if (orderBy.HasText() && OrderByHelper.AllowedOrderByFields.Contains(orderBy.ToLower())) { - orderByField = $"orderBy={orderBy}"; + orderByField = orderBy; } else if (orderByDescending.HasText() && OrderByHelper.AllowedOrderByFields.Contains(orderByDescending.ToLower())) { - orderByField = $"orderByDescending={orderByDescending}"; + orderByField = orderByDescending; descending = true; } From 14f78e20df9ce0fed0b6ce487f0f3064cab0b3b1 Mon Sep 17 00:00:00 2001 From: griffri Date: Fri, 11 Oct 2024 16:58:57 +0100 Subject: [PATCH 2/2] Update ReturnsFirstPageWithSecondItem_WhenCalledWithSmallPageSizeAndOrderByDescending to expect different items depending on alphabetical order --- .../API.Tests/Integration/GetCollectionTests.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/IIIFPresentation/API.Tests/Integration/GetCollectionTests.cs b/src/IIIFPresentation/API.Tests/Integration/GetCollectionTests.cs index a9e0318..7d06bab 100644 --- a/src/IIIFPresentation/API.Tests/Integration/GetCollectionTests.cs +++ b/src/IIIFPresentation/API.Tests/Integration/GetCollectionTests.cs @@ -337,14 +337,15 @@ public async Task Get_ChildFlat_ReturnsCorrectItem_WhenCalledWithSmallPageSizeAn collection.View.Page.Should().Be(1); collection.View.TotalPages.Should().Be(3); collection.Items!.Count.Should().Be(1); + collection.Items.OfType().First().Id.Should().Be("http://localhost/1/collections/FirstChildCollection"); } [Theory] - [InlineData("id")] - [InlineData("slug")] - [InlineData("created")] - public async Task Get_RootFlat_ReturnsFirstPageWithSecondItem_WhenCalledWithSmallPageSizeAndOrderByDescending(string field) + [InlineData("id", "NonPublic")] + [InlineData("slug", "NonPublic")] + [InlineData("created", "IiifCollection")] + public async Task Get_RootFlat_ReturnsFirstPageWithSecondItem_WhenCalledWithSmallPageSizeAndOrderByDescending(string field, string expectedItemId) { // Arrange var requestMessage = @@ -363,7 +364,8 @@ public async Task Get_RootFlat_ReturnsFirstPageWithSecondItem_WhenCalledWithSmal collection.View.Page.Should().Be(1); collection.View.TotalPages.Should().Be(3); collection.Items!.Count.Should().Be(1); - collection.Items.OfType().First().Id.Should().Be("http://localhost/1/collections/IiifCollection"); + + collection.Items.OfType().First().Id.Should().Be($"http://localhost/1/collections/{expectedItemId}"); } [Fact]