Skip to content

Commit

Permalink
fix response error
Browse files Browse the repository at this point in the history
  • Loading branch information
kenmoh committed Dec 2, 2023
1 parent 8fb6314 commit 277afc0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
13 changes: 1 addition & 12 deletions app/schema/movie_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MovieCreateSchema(BaseModel):
class MovieResponseSchema(MovieCreateSchema):
id: int
cover_image_url: str
average_rating: float | None
average_rating: float
reviews: list[ReviewResponseSchema]


Expand All @@ -26,21 +26,10 @@ class MovieResponseSchema(MovieCreateSchema):
""" START REVIEW SCHEMA """


# class ReviewResponseSchema(BaseModel):
# movie_id: int
# author: str
# comment: str
# rating: int | None


class ReviewCreateSchema(BaseModel):
author: str
comment: str
rating: int = Field(gt=0, le=5)


class AverageMovieReview(BaseModel):
average_rating: float


""" END REVIEW SCHEMA"""
6 changes: 6 additions & 0 deletions app/services/movie_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def get_movie(movie_id, db: session):
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Movie with ID: {movie_id} not found!",
)
if movie.reviews:
average_rating = sum(review.rating for review in movie.reviews) / len(movie.reviews)
movie.average_rating = average_rating
else:
movie.average_rating = 0.0

return movie


Expand Down

0 comments on commit 277afc0

Please sign in to comment.