Skip to content

Feature/pagination refactor - #2391

Open
MandarK07 wants to merge 3 commits into
fastapi:masterfrom
MandarK07:feature/pagination-refactor
Open

Feature/pagination refactor#2391
MandarK07 wants to merge 3 commits into
fastapi:masterfrom
MandarK07:feature/pagination-refactor

Conversation

@MandarK07

Copy link
Copy Markdown

Pull Request

Discussion: N/A

Description

This PR refactors the paginated response models to use a single Generic type, eliminating code duplication between users and items.
Previously, models.py defined separate models for each entity list:

  • UsersPublic(SQLModel)
  • ItemsPublic(SQLModel)
    This implementation replaces them with a single generic PaginatedResponse[T] model:
T = TypeVar("T")
class PaginatedResponse(SQLModel, Generic[T]):
    data: list[T]
    count: int

This ensures consistency across all current and future endpoints that require pagination (e.g., returning PaginatedResponse[UserPublic] or PaginatedResponse[ItemPublic]) and reduces boilerplate code in the models file.

## Checklist

- [ ] This PR links to a GitHub Discussion for the proposed code change.
- [ ] I added tests for the change.
- [ ] The new or updated tests fail on the main branch and pass on this PR.
- [ ] Coverage stays at 100%.
- [x] The documentation explains the change if needed.

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

Successfully merging this pull request may close these issues.

2 participants