Ejemplo n.º 1
0
def add_review(movie_rank: int, review_text: str, rating: int, username: str, repo: AbstractRepository):
    # Check that the movie exists.
    movie = repo.get_movie(movie_rank)
    if movie is None:
        raise NonExistentMovieException
    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

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

    # Update the repository.
    repo.add_review(review)
Ejemplo n.º 2
0
def add_review(movie_title: str, movie_year: int, username: str, review_text: str, rating: int, repo: AbstractRepository):
    # Check movie and user exists
    movie = repo.get_movie_by_title_and_year(movie_title, movie_year)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException
    
    # Create review
    review = make_review(user, movie, review_text, rating)

    # Add review
    repo.add_review(review)
Ejemplo n.º 3
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)