Skip to content

Commit

Permalink
Return specified field for orderByDescending= query
Browse files Browse the repository at this point in the history
  • Loading branch information
griffri committed Oct 11, 2024
1 parent 549bdf4 commit a804b16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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 ? "orderByDescending" : "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

0 comments on commit a804b16

Please sign in to comment.