Skip to content

added pagination for /trips endpoint - #178

Open
PhilySky7 wants to merge 2 commits into
devfrom
feature/pagination
Open

added pagination for /trips endpoint#178
PhilySky7 wants to merge 2 commits into
devfrom
feature/pagination

Conversation

@PhilySky7

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-pagination library with limit/offset pagination strategy
  • Modified the trips endpoint to return LimitOffsetPage[STripUserOutput] instead of list[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.

Comment thread src/trips/dao.py Outdated
Comment thread src/trips/services.py Outdated
Comment thread tests/test_trips.py
Comment thread src/trips/router.py Outdated
Comment thread src/trips/services.py Outdated
-pagination implemented at the database layer

@cosmofactory cosmofactory left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://uriyyo-fastapi-pagination.netlify.app/learn/tutorial_user_guide/add_to_route/#multiple-page-response-models-for-a-single-route-handler

Посмотри самый последний блок здесь, params не нужно никуда передавать

Comment thread src/trips/router.py
trips = await TripService.get_trips(db, limit)
@router.get("", response_model=LimitOffsetPage[STripUserOutput])
async def get_trips(
db: SessionDep, params: Annotated[LimitOffsetParams, Depends()]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params не нужны

Comment thread src/trips/dao.py
3. Return the result.
"""
query = select(Trip).options(joinedload(Trip.author))
return await apaginate(db, query, params)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params не нужны

Comment thread src/trips/dao.py
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):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params не нужны

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.

3 participants