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

Develop #29

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

Develop #29

wants to merge 11 commits into from

Conversation

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

Thank you for your hard work on this project! There are a few critical issues that need to be addressed before we can approve the pull request. Specifically, the get_movies and list_movies functions need to handle cases where no movies are found by returning a 404 Not Found error. Additionally, the create_movie function should check for duplicate entries and return a 409 Conflict error if necessary. There are also schema-related issues that need attention, such as ensuring MovieCreateSchema and MovieUpdateSchema do not inherit unnecessary fields. Once these issues are resolved, your code will be in great shape! Keep up the great 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.

):
total_items = db.query(MovieModel).count()
offset = (page - 1) * per_page
movies = db.query(MovieModel).order_by(MovieModel.id.desc()).offset(offset).limit(per_page).all()

Choose a reason for hiding this comment

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

The get_movies function should handle cases where no movies are found for the specified page by returning a 404 Not Found error with the message: "No movies found." This is a requirement from the task description.



def create_movie(db: Session, movie: MovieCreateSchema):
db_movie = MovieModel(**movie.dict())

Choose a reason for hiding this comment

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

The create_movie function should include a check for duplicate movies based on name and date. If a duplicate is found, it should return a 409 Conflict error with the message: "A movie with the name '{name}' and release date '{date}' already exists." .

Comment on lines 25 to 26
if existing_movie is None:
raise HTTPException(status_code=400)

Choose a reason for hiding this comment

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

The check for existing_movie is None is redundant because it contradicts the previous check for existing_movie. Remove this block to avoid unnecessary code execution.

Comment on lines +30 to +31
@router.get("/movies/", response_model=list[MovieReadSchema], status_code=200)
def list_movies(db: Session = Depends(get_db)):

Choose a reason for hiding this comment

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

The list_movies function should accept page and per_page query parameters to handle pagination. If no movies are found for the specified page, it should return a 404 Not Found error with the message: "No movies found." .

Comment on lines 46 to 47
@router.put("/movies/{movie_id}", response_model=MovieReadSchema, status_code=200)
def edit_movie(movie_id: int, movie: MovieUpdateSchema, db: Session = Depends(get_db)):

Choose a reason for hiding this comment

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

The edit_movie function should use the PATCH method instead of PUT to allow partial updates. Ensure that only the fields provided in the request body are updated, leaving all other fields unchanged.



class MovieBaseSchema(BaseModel):
id: int

Choose a reason for hiding this comment

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

The id field should not be part of MovieBaseSchema as it is not typically included in schemas meant for creation or updates. Consider removing it from MovieBaseSchema and adding it only to schemas where it is necessary, like MovieReadSchema.

country: Optional[str]


class MovieCreateSchema(MovieBaseSchema):

Choose a reason for hiding this comment

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

The MovieCreateSchema should not inherit from MovieBaseSchema if it requires different fields. Consider defining MovieCreateSchema independently to ensure it only includes the necessary fields for movie creation.

return value


class MovieUpdateSchema(MovieBaseSchema):

Choose a reason for hiding this comment

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

The MovieUpdateSchema should not inherit from MovieBaseSchema if it requires different fields. Consider defining MovieUpdateSchema independently to ensure it only includes the necessary fields for movie updates.

Comment on lines 73 to 76
@validator("id")
def validate_id(cls, value):
if movie_id := value:
return movie_id

Choose a reason for hiding this comment

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

The validate_id method in MovieReadSchema is redundant and does not perform any meaningful validation. Consider removing this method.

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.

Thank you for your submission! 🎉 While the code has several critical issues that need attention, the decision to approve is made to help you move forward with your learning journey. Here are the key points to address:

  1. Error Handling: Ensure that the create_movie function correctly handles duplicates by raising a 409 Conflict error, and that the delete_movie function raises a 404 Not Found error when a movie is not found.

  2. Schema Consistency: Consider inheriting MovieCreateSchema and MovieUpdateSchema from MovieBaseSchema to avoid redundancy. Use date instead of datetime.date for consistency in the release_date field.

  3. Pagination: Update the list_movies function to accept page and per_page parameters for proper pagination.

  4. Response Models: Remove the response_model from the delete route when using a 204 No Content status code.

  5. Redundant Checks: Remove unnecessary checks for db_movie being None to prevent incorrect error handling.

Please review these comments carefully and address them in future iterations to improve your code's robustness and adherence to RESTful standards. Keep up the good work and continue learning from these experiences! 🚀

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

Comment on lines 20 to 21
if db_movie is None:
raise HTTPException(status_code=400)

Choose a reason for hiding this comment

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

The check if db_movie is None: is unnecessary here because the previous check already handles the case where a duplicate movie exists. You should remove this block to avoid raising a 400 Bad Request error incorrectly.

Comment on lines +61 to +62
if db_movie is None:
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 check if db_movie is None: is redundant because the previous check if not db_movie: already handles the case where the movie is not found. You should remove this block to avoid raising a 400 Bad Request error incorrectly.

Comment on lines 73 to 74
if not db_movie:
return None

Choose a reason for hiding this comment

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

Instead of returning None, you should raise a 404 Not Found error when the movie is not found. This will provide a more consistent API response and better error handling.

Comment on lines +19 to +20
def list_movies(db: Session = Depends(get_db)):
db_movie = get_movies(db)

Choose a reason for hiding this comment

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

The list_movies function should accept page and per_page parameters to pass them to the get_movies function. This will allow for proper pagination of the movie list.

return db_movie


@router.delete("/movies/{movie_id}", response_model=MovieReadSchema, status_code=204)

Choose a reason for hiding this comment

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

The delete route should not specify a response_model when the status code is 204 No Content. Consider removing the response_model parameter to align with the semantics of a 204 response.


class MovieBaseSchema(BaseModel):
name: str
date: datetime.date

Choose a reason for hiding this comment

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

Use date instead of datetime.date for the date field to be consistent with the release_date field in MovieCreateSchema.

country: Optional[str]


class MovieCreateSchema(BaseModel):

Choose a reason for hiding this comment

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

Consider inheriting MovieCreateSchema from MovieBaseSchema to ensure consistency and avoid redundancy in field definitions.

return value


class MovieUpdateSchema(BaseModel):

Choose a reason for hiding this comment

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

Consider inheriting MovieUpdateSchema from MovieBaseSchema to ensure consistency and avoid redundancy in field definitions.

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