Fix pagination to return last page data when invalid page numbers are requested#14
Merged
Merged
Conversation
Co-authored-by: ErlendEllefsen <35459838+ErlendEllefsen@users.noreply.github.com>
Co-authored-by: ErlendEllefsen <35459838+ErlendEllefsen@users.noreply.github.com>
Co-authored-by: ErlendEllefsen <35459838+ErlendEllefsen@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Disallow invalid page numbers
Fix pagination to return last page data when invalid page numbers are requested
Jun 26, 2025
Collaborator
There was a problem hiding this comment.
??? Do not change my .net version. I use 9
Author
There was a problem hiding this comment.
Reverted both project files back to .NET 9.0. The downgrade to .NET 8.0 was unnecessary for the pagination fix. Commit: 12b8f90
Collaborator
There was a problem hiding this comment.
Do not change my .net version
Author
There was a problem hiding this comment.
The .NET version has been restored to the original net9.0 in commit 9af3ccb. Both project files are now back to their original state.
Co-authored-by: ErlendEllefsen <35459838+ErlendEllefsen@users.noreply.github.com>
Erlend Ellefsen (erlendellefsen)
approved these changes
Sep 1, 2025
Collaborator
Erlend Ellefsen (erlendellefsen)
left a comment
There was a problem hiding this comment.
lgtm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When users request a page number that exceeds the total number of available pages, the API returns empty data while showing the invalid page number in metadata. This creates a poor user experience where requesting page 2 of a 1-page dataset returns no results.
Before this fix:
{ "data": [], "meta": { "pagination": { "totalResources": 6, "totalPages": 1, "currentPage": 2, "pageSize": 10 } } }Solution
This PR implements page number clamping to ensure users always receive the closest valid page:
After this fix:
{ "data": [/* actual data from page 1 */], "meta": { "pagination": { "totalResources": 6, "totalPages": 1, "currentPage": 1, "pageSize": 10 } } }Changes Made
Core Logic
ApplyPagination: Added page number validation and clamping before applying skip/takeCreatePaginationMetaAsync: Return the effective (clamped) page number in metadata instead of the originally requested pageClamping Algorithm
Testing Improvements
Backwards Compatibility
This change maintains full backwards compatibility while improving user experience:
Fixes #3.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.