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

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

Solution #41

wants to merge 2 commits into from

Conversation

raychw
Copy link

@raychw raychw commented Feb 8, 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.

Great job on implementing the FastAPI application! 🎉 While there are a few areas for improvement, such as refining error handling in the create_movie function and ensuring data integrity in create_objects, these are minor issues that don't critically impact the functionality. Keep up the good work, and consider addressing these points in future iterations to enhance your code quality even further! 😊

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

Comment on lines +74 to +77
@router.patch("/movies/{movie_id}/")
def patch_movie(movie_id: int, movie: MovieUpdateSchema, db: Session = Depends(get_db)):
update_movie(db, movie_id, movie)
return HTTPException(status_code=200, detail="Movie updated successfully.")

Choose a reason for hiding this comment

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

The patch_movie function should return a success response (e.g., a JSON message or the updated movie data) instead of raising an HTTPException with a 200 status code. Raising an HTTPException is typically used for error responses.

Comment on lines +69 to +71
@router.delete("/movies/{movie_id}/", status_code=204)
def remove_movie(movie_id: int, db: Session = Depends(get_db)):
delete_movie(db, movie_id)

Choose a reason for hiding this comment

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

The remove_movie function should check if the movie with the given movie_id exists before attempting to delete it. If the movie does not exist, it should raise an HTTPException with a 404 status code and a message indicating that the movie was not found.

Comment on lines +20 to +28
def create_objects(data: List[str], model, db: Session):
objects = [model(name=element) for element in data]
db.add_all(objects)
db.commit()

for obj in objects:
db.refresh(obj)

return objects

Choose a reason for hiding this comment

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

The create_objects function should check if the objects already exist in the database before creating new ones. This will prevent duplicate entries and ensure data integrity.

Comment on lines +72 to +75
except SQLAlchemyError:

db.rollback()
raise HTTPException(status_code=400, detail="Invalid input data.")

Choose a reason for hiding this comment

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

The error handling in the create_movie function is too broad. Consider catching specific SQLAlchemy exceptions to provide more detailed error messages and improve debugging.

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