Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

skyfoxwork
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. Schema Consistency: Ensure that the movies field in MovieListResponseSchema is populated with instances of MovieDetailResponseSchema to maintain consistency with the schema definition. This is crucial for ensuring that the API responses align with the expected structure.

  2. Pagination Logic:

    • Make sure that next_page does not exceed total_pages to avoid generating invalid URLs.
    • Check if page - 1 is valid (greater than 0) before constructing prev_page to prevent invalid URLs.
  3. Schema Definitions: Verify that MovieListResponseSchema and MovieDetailResponseSchema are correctly defined in schemas.movies and match the expected response structure.

  4. Code Cleanliness: There are commented-out lines related to the movies router. If you intend to use the movies 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

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)

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

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,

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}"

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}"

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]

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. Schema Consistency: You've successfully ensured that the movies field in MovieListResponseSchema is populated with instances of MovieDetailResponseSchema, maintaining consistency with the schema definition. This is crucial for the API responses to function correctly.

  2. Pagination Logic: The pagination logic is now correctly implemented:

    • The next_page does not exceed total_pages, which prevents the generation of invalid URLs.
    • The prev_page is constructed only if page - 1 is valid (greater than 0), ensuring that all URLs are valid.
  3. Schema Definitions: Both MovieListResponseSchema and MovieDetailResponseSchema are well-defined and align with the expected response structure, which is essential for the API's reliability.

  4. 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,

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,

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}"

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.

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