Beispiel #1
0
def get_reviews_for_movie(movie_rank: int, repo: AbstractRepository):
    movie = repo.get_movie_by_rank(movie_rank)

    if movie is None:
        raise ServicesException('Movie does not exist in the repository')

    return repo.get_reviews_for_movie(movie)
Beispiel #2
0
def create_review(movie_rank: int, review_text: str, rating: int,
                  user_name: str, repo: AbstractRepository):
    # Check that the Movie exists.
    movie = repo.get_movie_by_rank(movie_rank)
    if movie is None:
        raise ServicesException('Movie does not exist in the repository')

    # Check that the user exists.
    user = repo.get_user(user_name)
    if user is None:
        raise ServicesException('User does not exist in the repository')

    # Create review
    review = Review(movie, review_text, rating)

    # Add review to list of user reviews (and consequently to list of Movie reviews)
    user.add_review(review)

    # Update the repository with new Review.
    repo.add_review(review)