-
Notifications
You must be signed in to change notification settings - Fork 58
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 #26
base: dev
Are you sure you want to change the base?
solution #26
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.
It looks like there are a few critical issues that need to be addressed before we can approve the Pull Request. The update_movie
function should be enhanced to update related entities like genres, actors, and languages if required by the application's specifications. Additionally, the MovieUpdateSchema
should be consistent with the fields that are actually updatable in the application logic. The validate
method in MovieCreateSchema
has a logical error that needs correction to ensure it aligns with the application's requirements. Lastly, handling potential IntegrityError
exceptions during database operations will improve error handling and provide better feedback to users. Once these issues are resolved, your code will be in great shape! Keep up the good work! 🚀
✨ 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.
# movie creation | ||
@router.post("/movies/", response_model=MovieDetailSchema, status_code=201) | ||
def create_movie(movie: MovieCreateSchema, db: Session = Depends(get_db)) -> MovieDetailSchema: | ||
movie_found = db.query(MovieModel).filter(MovieModel.name == movie.name, MovieModel.date == movie.date).first() |
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 handling potential IntegrityError
exceptions that might occur during the database commit operations. This will help in providing more informative error messages to the client.
src/routes/movies.py
Outdated
def update_movie(movie_id: int, movie: MovieCreateSchema, db: Session = Depends(get_db)) -> MovieDetailSchema: | ||
existing_movie = db.get(MovieModel, movie_id) | ||
|
||
if not existing_movie: | ||
raise HTTPException(status_code=404, detail="Movie with the given ID was not found.") | ||
|
||
existing_movie.name = movie.name | ||
existing_movie.date = movie.date | ||
existing_movie.score = movie.score | ||
existing_movie.overview = movie.overview | ||
existing_movie.status = movie.status | ||
existing_movie.budget = movie.budget | ||
existing_movie.revenue = movie.revenue |
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 update_movie
function currently updates only the basic attributes of the movie. If the application's requirements include updating related entities like genres, actors, and languages, you should implement logic to handle these updates as well.
src/schemas/movies.py
Outdated
@field_validator("date") | ||
def validate(cls, value: str | datetime.date): | ||
if value < datetime.date.today() + datetime.timedelta(days=365): | ||
raise ValueError("Date must be at least one year in future") | ||
return value |
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 validate
method for the date
field in MovieCreateSchema
has a logical error. The condition value < datetime.date.today() + datetime.timedelta(days=365)
will raise an error if the date is not at least one year in the future, which might not be the intended behavior. Ensure that the logic aligns with the application's requirements.
src/schemas/movies.py
Outdated
class MovieUpdateSchema(BaseModel): | ||
name: str | ||
date: datetime.date | ||
score: float = Field(ge=0, le=100) | ||
overview: str | ||
status: str | ||
budget: float = Field(ge=0) | ||
revenue: float = Field(ge=0) | ||
countries: list[str] | ||
genres: list[str] | ||
actors: list[str] | ||
languages: list[str] |
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 MovieUpdateSchema
should be consistent with the fields that are actually updatable in the application logic. Ensure that this schema matches the fields that are intended to be updated in the update_movie
function.
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.
Great job on your submission! 🎉 Your code is well-structured and aligns with the task requirements, especially in updating related entities and handling exceptions. However, there are a few areas for improvement:
-
Country Code Validation: Ensure the
code
field inCountryBase
matches the expected format for country codes, typically two uppercase letters. Consider using a regex pattern or a custom validator. -
Date Validation Method: Rename the
validate
method tovalidate_date
to align with Pydantic's conventions. Ensure it handles both string anddatetime.date
inputs correctly. -
IntegrityError Handling: While you handle
IntegrityError
exceptions, providing more specific feedback to users about potential causes, like duplicate entries, would enhance user experience. -
Default Country Code: Using 'default_code' as a placeholder isn't ideal. Consider generating a meaningful default or ensuring the code is provided in the
MovieCreateSchema
.
These improvements will enhance the robustness and user-friendliness 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! ✨
No description provided.