-
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 #41
base: main
Are you sure you want to change the base?
Solution #41
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.
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! ✨
@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.") |
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 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.
@router.delete("/movies/{movie_id}/", status_code=204) | ||
def remove_movie(movie_id: int, db: Session = Depends(get_db)): | ||
delete_movie(db, movie_id) |
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 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.
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 |
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 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.
except SQLAlchemyError: | ||
|
||
db.rollback() | ||
raise HTTPException(status_code=400, detail="Invalid input data.") |
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 error handling in the create_movie
function is too broad. Consider catching specific SQLAlchemy exceptions to provide more detailed error messages and improve debugging.
No description provided.