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

Examples of Paging and Sorting for relevant endpoints. #555

Open
DerekChasse opened this issue May 22, 2023 · 2 comments
Open

Examples of Paging and Sorting for relevant endpoints. #555

DerekChasse opened this issue May 22, 2023 · 2 comments

Comments

@DerekChasse
Copy link

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.

@DerekChasse
Copy link
Author

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

@DerekChasse
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant