added pagination for /trips endpoint - #178
Open
PhilySky7 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements pagination support for the trips list endpoint by integrating the fastapi-pagination library. The changes replace the simple list response with a paginated response structure that includes metadata like total count, limit, and offset.
Key Changes
- Added pagination support using
fastapi-paginationlibrary with limit/offset pagination strategy - Modified the trips endpoint to return
LimitOffsetPage[STripUserOutput]instead oflist[STripUserOutput] - Refactored
TripDAO.get_all_trips()to return a SQLAlchemy query statement instead of executing it, enabling pagination at the service layer
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
pyproject.toml |
Added fastapi-pagination>=0.15.0 dependency |
src/trips/router.py |
Updated endpoint to use LimitOffsetPage response model and LimitOffsetParams dependency; added pagination initialization to router |
src/trips/services.py |
Modified get_trips() to use apaginate() for pagination with query transformation |
src/trips/dao.py |
Refactored get_all_trips() from async query executor to synchronous query builder returning a Select statement |
tests/test_trips.py |
Updated test to verify paginated response structure with items, total, limit, and offset fields |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cosmofactory
requested changes
Nov 10, 2025
-pagination implemented at the database layer
cosmofactory
requested changes
Dec 3, 2025
cosmofactory
left a comment
Owner
There was a problem hiding this comment.
Посмотри самый последний блок здесь, params не нужно никуда передавать
| trips = await TripService.get_trips(db, limit) | ||
| @router.get("", response_model=LimitOffsetPage[STripUserOutput]) | ||
| async def get_trips( | ||
| db: SessionDep, params: Annotated[LimitOffsetParams, Depends()] |
| 3. Return the result. | ||
| """ | ||
| query = select(Trip).options(joinedload(Trip.author)) | ||
| return await apaginate(db, query, params) |
| query = select(Trip).options(joinedload(Trip.author)).limit(limit) | ||
| result = await db.execute(query) | ||
| return result.unique().scalars().all() | ||
| async def get_all_trips(cls, db: AsyncSession, params): |
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.
No description provided.