Examples of Paging and Sorting for relevant endpoints.
I think an example of how one would achieve paging and sorting using this template would be beneficial to those using it.
Maybe this belongs in https://github.com/ardalis/ApiEndpoints? Not quite sure.
Maybe something this this?
public class ListProjectRequest
{
public const string ROUTE = "/Project";
public string BuildRoute(int page, int pageSize)
{
return $"{ROUTE}?page={page}&pageSize={pageSize}";
}
[FromQuery(Name = "page")]
public int Page { get; set; }
[FromQuery(Name = "pageSize")]
public int PageSize { get; set; } = 20;
}
This certainly isn't enough as this info needs to make it's way to a paging aware Specification
Paging seems to be relatively simple, and I've passed the above example request to an appropriate Specification. If desired, I can build a PR that shows this to include in the template.
Turning attention to Sorting however... I'm curious as to how that would be achieved. Having a query parameter which represents the order definition using ODATA seems to be an option however I'm unsure how to turn the ODATA representation into a LINQ expression and pass that down to the Specification.
@ardalis does the Specification framework allow for OData? Supporting all of that ODATA allows (Select, Filter, Expand etc...) feels contrary to Specifications, but supporting the 'OrderBy' subset of the standard feels like it deserves consideration.
Supporting ODATA's orderby feature feels like a more consistent implementation rather than handcrafting bespoke sorting options into each request.
Thoughts?