def get_movie(movie_id: int, repo: AbstractRepository): movie = repo.get_movie_by_index(movie_id) if movie is None: raise NonExistentMovieException return movie_to_dict(movie)
def get_reviews_for_movie(movie_id, repo: AbstractRepository): movie = repo.get_movie_by_index(movie_id) if movie is None: raise NonExistentMovieException return reviews_to_dict(movie.reviews)
def add_review(review_text: str, username: str, movie_id: int, rating: int, repo: AbstractRepository): # Check that the movie exists. movie = repo.get_movie_by_index(movie_id) if movie is None: raise NonExistentMovieException # Check that the user exists user = repo.get_user(username) if user is None: raise UnknownUserException # Create review review = make_review(review_text=review_text, user=user, movie=movie, rating=rating) # Update the repository repo.add_review(review)