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

Add pagination classes and extensions #6

Merged
merged 2 commits into from
May 15, 2024
Merged

Conversation

sunecko
Copy link
Contributor

@sunecko sunecko commented May 14, 2024

Add PaginatedRequest and PaginatedResponse classes to handle data pagination in the API. Also include the ToPaginatedResult extension for paginating data collections. These additions facilitate the implementation of pagination in API responses.

public class ExampleRequest: PaginatedRequest
{
    public string Name { get; set; } = string.Empty;
}

public class ExampleResponse
{
    public string Message { get; set; } = string.Empty;
}

public class ExampleEndpoint: Endpoint<ExampleRequest, PaginatedResponse<ExampleResponse>>
{
    public override void Configure()
    {
        Get("/example");
        AllowAnonymous();
    }

    public override async Task HandleAsync(ExampleRequest req, CancellationToken ct)
    {
        var data = new List<ExampleResponse>
        {
            new ExampleResponse { Message = "Hello Fast Endpoints" },
            new ExampleResponse { Message = "Hello BrodSquad" },
        };

        await SendOkAsync(data.ToPaginatedResult(req.PageNumber, req.PageSize));
    }
}

@sunecko sunecko requested a review from CerealKiller97 May 14, 2024 13:58
@CerealKiller97 CerealKiller97 merged commit fdc045c into BrosSquad:main May 15, 2024
1 check passed
@CerealKiller97
Copy link
Member

@hectorrhg Thanks for the contribution 🎉.

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

Successfully merging this pull request may close these issues.

2 participants