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 #26

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

solution #26

wants to merge 4 commits into from

Conversation

dxrrkwm
Copy link

@dxrrkwm dxrrkwm commented Jan 22, 2025

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.


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()

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.

Comment on lines 173 to 185
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

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.

Comment on lines 56 to 60
@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

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.

Comment on lines 73 to 84
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]

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.

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 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 in CountryBase 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 to validate_date to align with Pydantic's conventions. Ensure it handles both string and datetime.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! ✨

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