Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix orderByDescending behaviour #92

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/IIIFPresentation/API.Tests/Integration/GetCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Collection>().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 =
Expand All @@ -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<Collection>().First().Id.Should().Be("http://localhost/1/collections/IiifCollection");

collection.Items.OfType<Collection>().First().Id.Should().Be($"http://localhost/1/collections/{expectedItemId}");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ public async Task<IActionResult> 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()));
Expand Down
4 changes: 2 additions & 2 deletions src/IIIFPresentation/API/Infrastructure/ControllerBaseX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading