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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

solution #32

wants to merge 1 commit into from

Conversation

Morphin20th
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.

Great job on implementing the core functionality and meeting the task requirements! 🎉 While there are a few areas for improvement, such as enhancing validation in models and handling potential errors more gracefully, these are minor and do not impact the overall functionality. Keep up the good work and consider the suggestions for future enhancements! 😊

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

@@ -1,7 +1,7 @@
"""initial migration

Revision ID: ea3a65568bd9
Revises:
Revises:

Choose a reason for hiding this comment

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

The Revises identifier is missing. This should be set to the revision ID of the previous migration if there is one, or None if this is the first migration. This is important for Alembic to understand the order of migrations.

db.add(created_movie)
db.commit()
db.refresh(created_movie)
return created_movie

Choose a reason for hiding this comment

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

In the create_movie function, after adding new genres, actors, and languages, consider using db.flush() to ensure that these records are persisted before associating them with the movie. This can help prevent issues if the transaction is rolled back.

db.add(created_movie)
db.commit()
db.refresh(created_movie)
return created_movie

Choose a reason for hiding this comment

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

The create_movie function does not handle potential integrity errors when adding a new movie. Consider adding a try-except block around the db.commit() to catch and handle SQLAlchemyError exceptions.

if not db_movie:
raise HTTPException(status_code=404, detail="Movie with the given ID was not found.")
db.delete(db_movie)
db.commit()

Choose a reason for hiding this comment

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

In the delete_movie function, consider returning a success message or status after the movie is successfully deleted to provide feedback to the client.

"type": "value_error.number.not_ge"
}
]
)

Choose a reason for hiding this comment

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

The check for page being less than 1 is redundant because the Query parameter already enforces ge=1. You can remove this check to simplify the code.

movies_query = movies.order_by(-MovieModel.id).offset(offset).limit(per_page).all()

if not movies_query:
raise HTTPException(status_code=404, detail="No movies found.")

Choose a reason for hiding this comment

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

Raising a 404 error when no movies are found might not be appropriate for a list endpoint. Consider returning an empty list instead, as this is a common practice for list endpoints.

@router.delete("/movies/{movie_id}", status_code=204)
def remove_movie(movie_id: int, db: Session = Depends(get_db)):
delete_movie(db, movie_id)
return

Choose a reason for hiding this comment

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

The remove_movie function returns None, which is fine for a 204 status code. However, consider returning a success message or status for better client feedback.

@staticmethod
def validate_date(value):
if value > date.today() + timedelta(days=365):
raise ValueError("The date must not be more than one year in the future")

Choose a reason for hiding this comment

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

The validate_date function checks if the date is more than one year in the future. Consider also checking if the date is in the past, depending on your application's requirements.



class MovieCreate(BaseModel):
name: str

Choose a reason for hiding this comment

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

In the MovieCreate model, consider adding validation constraints similar to those in MovieBase, such as max_length for name and range checks for score, to ensure data consistency.

score: Optional[float] = None
overview: Optional[str] = None
status: Optional[MovieStatusEnum] = None
budget: Optional[float] = None

Choose a reason for hiding this comment

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

In the MovieUpdate model, consider adding validation constraints similar to those in MovieBase, such as max_length for name and range checks for score, to ensure data consistency.

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