-
Notifications
You must be signed in to change notification settings - Fork 43
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
Solution-py-fastapi-homework-1-task #10
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this project! 😊 While your code largely meets the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Schema Consistency: Ensure that the
movies
field inMovieListResponseSchema
is populated with instances ofMovieDetailResponseSchema
to maintain consistency with the schema definition. This is crucial for ensuring that the API responses align with the expected structure. -
Pagination Logic:
- Make sure that
next_page
does not exceedtotal_pages
to avoid generating invalid URLs. - Check if
page - 1
is valid (greater than 0) before constructingprev_page
to prevent invalid URLs.
- Make sure that
-
Schema Definitions: Verify that
MovieListResponseSchema
andMovieDetailResponseSchema
are correctly defined inschemas.movies
and match the expected response structure. -
Code Cleanliness: There are commented-out lines related to the
movies
router. If you intend to use themovies
router, ensure it is correctly imported and included in the application. Otherwise, consider removing these lines to clean up the code.
Once these issues are resolved, your code will be in great shape! Keep up the great work, and feel free to reach out if you have any questions or need further assistance. 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/main.py
Outdated
@@ -1,6 +1,7 @@ | |||
from fastapi import FastAPI | |||
|
|||
from routes import movie_router | |||
# from routes import movies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is commented out. If you intend to use the movies
router, ensure it is correctly imported and included in the application. Otherwise, you can remove this line to clean up the code.
src/main.py
Outdated
@@ -10,3 +11,4 @@ | |||
api_version_prefix = "/api/v1" | |||
|
|||
app.include_router(movie_router, prefix=f"{api_version_prefix}/theater", tags=["theater"]) | |||
# app.include_router(movies.router) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is also commented out. If you need to include the movies.router
, make sure it is correctly imported and uncomment this line. Otherwise, consider removing it if it's not needed.
@@ -2,9 +2,41 @@ | |||
from sqlalchemy.orm import Session | |||
|
|||
from database import get_db, MovieModel | |||
|
|||
from schemas.movies import MovieListResponseSchema, MovieDetailResponseSchema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that MovieListResponseSchema
and MovieDetailResponseSchema
are correctly defined in schemas.movies
and match the expected response structure.
raise HTTPException(status_code=404, detail="No movies found.") | ||
|
||
return MovieListResponseSchema( | ||
movies=movies_with_pagination, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The movies
field in MovieListResponseSchema
should likely be populated with movie_list_schema
instead of movies_with_pagination
to ensure the response matches the schema.
] | ||
total_items = db.query(MovieModel).count() | ||
total_pages = (total_items + per_page - 1) // per_page | ||
prev_page = f"/theater/movies/?page={page - 1}&per_page={per_page}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider checking if page - 1
is valid (greater than 0) before constructing prev_page
to avoid generating invalid URLs.
total_items = db.query(MovieModel).count() | ||
total_pages = (total_items + per_page - 1) // per_page | ||
prev_page = f"/theater/movies/?page={page - 1}&per_page={per_page}" | ||
next_page = f"/theater/movies/?page={page + 1}&per_page={per_page}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that next_page
does not exceed total_pages
to avoid generating invalid URLs.
|
||
|
||
class MovieListResponseSchema(BaseModel): | ||
movies: list[MovieDetailResponseSchema] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the movies
field in MovieListResponseSchema
is populated with instances of MovieDetailResponseSchema
in the route handler to maintain consistency with the schema definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
Great job on addressing the issues in your code! 🎉 Here are some key points to keep in mind:
-
Schema Consistency: You've successfully ensured that the
movies
field inMovieListResponseSchema
is populated with instances ofMovieDetailResponseSchema
, maintaining consistency with the schema definition. This is crucial for the API responses to function correctly. -
Pagination Logic: The pagination logic is now correctly implemented:
- The
next_page
does not exceedtotal_pages
, which prevents the generation of invalid URLs. - The
prev_page
is constructed only ifpage - 1
is valid (greater than 0), ensuring that all URLs are valid.
- The
-
Schema Definitions: Both
MovieListResponseSchema
andMovieDetailResponseSchema
are well-defined and align with the expected response structure, which is essential for the API's reliability. -
Code Cleanliness: Your code is clean, with no unnecessary commented-out lines, and the
movies
router is correctly imported and included in the application.
While the code is approved, remember to always review the comments and suggestions to further improve your coding skills. Addressing critical issues, like schema consistency and pagination logic, is vital for the functionality of your code. Keep up the great work and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
|
||
return MovieListResponseSchema( | ||
movies=movies_with_pagination, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The movies
field in MovieListResponseSchema
should be populated with movie_list_schema
instead of movies_with_pagination
to ensure consistency with the schema definition.
total_items=total_items, | ||
total_pages=total_pages, | ||
prev_page=None if page == 1 else prev_page, | ||
next_page=None if page == total_pages else next_page, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that next_page
does not exceed total_pages
to avoid generating invalid URLs.
] | ||
total_items = db.query(MovieModel).count() | ||
total_pages = (total_items + per_page - 1) // per_page | ||
prev_page = f"/theater/movies/?page={page - 1}&per_page={per_page}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if page - 1
is valid (greater than 0) before constructing prev_page
to prevent invalid URLs.
No description provided.