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

Add CRUD endpoints for movies with pagination and validation #38

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

Conversation

Lev2098
Copy link

@Lev2098 Lev2098 commented Feb 4, 2025

Implemented CRUD operations for managing movies, including creation, reading, updating, and deletion. Added pagination to the movie listing endpoint and incorporated robust validation with Pydantic schemas. Updated dependencies in pyproject.toml to support new features like extra types and country validation.

Implemented CRUD operations for managing movies, including creation, reading, updating, and deletion. Added pagination to the movie listing endpoint and incorporated robust validation with Pydantic schemas. Updated dependencies in `pyproject.toml` to support new features like extra types and country validation.
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! Your implementation is mostly correct and meets the task requirements, but there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Budget and Revenue Fields: The budget and revenue fields in MovieCreateResponseSchema are set to gt=0, which prevents them from being zero. Since budgets and revenues can start at zero, especially when a movie is first created, please change gt=0 to ge=0 to allow zero values.

  2. Committing Within Loops: Committing within loops for genres, actors, and languages can lead to inefficiencies and potential performance issues. It's better to commit once after processing all items to improve performance.

  3. Typo in Error Message: There's a typo in the error message: 'is requir' should be 'are required'. This affects the clarity of the error message and needs to be corrected.

Once these issues are resolved, your code will be in great shape! Keep up the excellent 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.

Comment on lines +105 to +108
if not movie_data.name or not movie_data.date or not movie_data.overview or not movie_data.status:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Fields 'name', 'date', 'overview' and 'status' is requir to create movie."

Choose a reason for hiding this comment

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

There is a typo in the error message: 'is requir' should be 'are required'. This is an error related to the task requirements as it affects the clarity of the error message.

if not genre:
genre = GenreModel(name=genre_name)
db.add(genre)
db.commit()

Choose a reason for hiding this comment

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

Committing within a loop can lead to inefficiencies and potential performance issues. Consider committing once after all genres have been processed.

if not actor:
actor = ActorModel(name=actor_name)
db.add(actor)
db.commit()

Choose a reason for hiding this comment

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

Committing within a loop can lead to inefficiencies and potential performance issues. Consider committing once after all actors have been processed.

if not language:
language = LanguageModel(name=language_name)
db.add(language)
db.commit()

Choose a reason for hiding this comment

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

Committing within a loop can lead to inefficiencies and potential performance issues. Consider committing once after all languages have been processed.

Comment on lines +45 to +46
budget: float = Field(gt=0)
revenue: float = Field(gt=0)

Choose a reason for hiding this comment

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

The budget and revenue fields in MovieCreateResponseSchema are set to gt=0, which means they cannot be zero. Typically, budgets and revenues can start at zero, especially when a movie is first created. Consider changing gt=0 to ge=0 to allow zero values.

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.

Great job on implementing the movie routes in FastAPI! 🎬 While your code is mostly correct, there are a few critical issues that need attention:

  1. Committing Within Loops: Currently, the code commits changes to the database within loops for genres, actors, and languages. This can lead to inefficiencies and potential performance issues. It's recommended to commit once after processing all items to enhance performance.

  2. Typo in Error Message: There's a typo in the error message on line 109: 'is requir' should be corrected to 'are required' to improve clarity.

  3. Budget and Revenue Fields: The budget and revenue fields in both MovieCreateResponseSchema and MovieUpdateResponseSchema are set to gt=0, which prevents them from being zero. Since budgets and revenues can start at zero, especially when a movie is first created, please change gt=0 to ge=0 to allow zero values.

These adjustments are crucial for the functionality and performance of your code. Addressing these issues will not only improve your current implementation but also help you avoid similar problems in the future. Keep up the good work, and continue learning from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

if not genre:
genre = GenreModel(name=genre_name)
db.add(genre)
db.commit()

Choose a reason for hiding this comment

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

Committing within the loop for genres can lead to inefficiencies. Consider moving the commit outside the loop to improve performance.

if not actor:
actor = ActorModel(name=actor_name)
db.add(actor)
db.commit()

Choose a reason for hiding this comment

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

Committing within the loop for actors can lead to inefficiencies. Consider moving the commit outside the loop to improve performance.

if not language:
language = LanguageModel(name=language_name)
db.add(language)
db.commit()

Choose a reason for hiding this comment

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

Committing within the loop for languages can lead to inefficiencies. Consider moving the commit outside the loop to improve performance.

if not movie_data.name or not movie_data.date or not movie_data.overview or not movie_data.status:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Fields 'name', 'date', 'overview' and 'status' is requir to create movie."

Choose a reason for hiding this comment

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

Typo in error message: 'is requir' should be 'are required'.

score: float = Field(ge=0, le=100)
overview: str
status: MoviesStatusEnumSchema
budget: float = Field(gt=0)

Choose a reason for hiding this comment

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

The budget field is set to gt=0, which prevents it from being zero. Change gt=0 to ge=0 to allow zero values.

overview: str
status: MoviesStatusEnumSchema
budget: float = Field(gt=0)
revenue: float = Field(gt=0)

Choose a reason for hiding this comment

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

The revenue field is set to gt=0, which prevents it from being zero. Change gt=0 to ge=0 to allow zero values.

score: Optional[float] = Field(None, ge=0, le=100)
overview: Optional[str] = None
status: Optional[MoviesStatusEnumSchema] = None
budget: Optional[float] = Field(None, gt=0)

Choose a reason for hiding this comment

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

The budget field in MovieUpdateResponseSchema is set to gt=0, which prevents it from being zero. Change gt=0 to ge=0 to allow zero values.

overview: Optional[str] = None
status: Optional[MoviesStatusEnumSchema] = None
budget: Optional[float] = Field(None, gt=0)
revenue: Optional[float] = Field(None, gt=0)

Choose a reason for hiding this comment

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

The revenue field in MovieUpdateResponseSchema is set to gt=0, which prevents it from being zero. Change gt=0 to ge=0 to allow zero values.

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