Exemplo n.º 1
0
def add_to_watchlist(movie_id: int, username: str, repo: AbstractRepository):

    if repo.get_user(username) is None:
        raise UnknownUserException

    if repo.get_movie(movie_id) is None:
        raise NonExistentMovieException

    repo.add_to_watchlist(repo.get_movie(movie_id), repo.get_user(username))
Exemplo n.º 2
0
def get_movie(movie_id: int, repo: AbstractRepository):
    movie = repo.get_movie(movie_id)

    if movie is None:
        raise NonExistentMovieException

    return movie_to_dict(movie)
Exemplo n.º 3
0
def get_reviews_for_movie(movie_id, repo: AbstractRepository):
    movie = repo.get_movie(movie_id)

    if movie is None:
        raise NonExistentMovieException

    return reviews_to_dict(movie.reviews)
Exemplo n.º 4
0
def add_to_watchlist(movie_id: int, username: str, repo: AbstractRepository):
    movie = repo.get_movie(movie_id)
    # if movie is None:
    #     raise NonExistentMovieException

    user = repo.get_user(username)
    # if user is None:
    #     raise UnknownUserException

    repo.add_to_watchlist(movie, user)
Exemplo n.º 5
0
def remove_from_watchlist(movie_id: int, username: str,
                          repo: AbstractRepository):

    movie = repo.get_movie(movie_id)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    repo.remove_from_watchlist(movie, user)
Exemplo n.º 6
0
def add_review(movie_id: int, review_text: str, username: str,
               repo: AbstractRepository):
    movie = repo.get_movie(movie_id)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    review = make_review(review_text=review_text, user=user, movie=movie)

    repo.add_review(review)
    return review_to_dict(review)
Exemplo n.º 7
0
def add_review(movie_id: int, review_text: str, username: str, repo: AbstractRepository):
    # Check that the movie exists.
    movie = repo.get_movie(movie_id)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    # Create review.
    review = make_review(review_text, user, movie)

    # Update the repository.
    repo.add_review(review)
Exemplo n.º 8
0
def get_movie_by_a_rank(rank, repo: AbstractRepository):
    movie = repo.get_movie(rank)
    movie_dict = movie_to_dict(movie)
    prev_rank = next_rank = None
    if movie.rank == 1:
        prev_rank = None
        next_rank = 4
    elif movie.rank == 1000:
        prev_rank = 997
        next_rank = None
    elif 1 < movie.rank < 1000:
        prev_rank = movie.rank - 3
        next_rank = movie.rank + 3

    return movie_dict, prev_rank, next_rank