Example #1
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, repo)
Example #2
0
def add_image_link(movie_id: int, link: str, repo: AbstractRepository):
    movie = repo.get_movie(movie_id)
    if movie is None:
        raise NonExistentMovieException

    # Update the repository.
    repo.add_image_link(link, movie)
Example #3
0
def get_comments_for_movie(movie_id, repo: AbstractRepository):
    movie = repo.get_movie(movie_id)

    if movie is None:
        raise NonExistentMovieException

    return comments_to_dict(movie.comments)
Example #4
0
def add_rating(movie_id: int, rating: float, 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:
        user = User("Guest account", "Abcd1234")

    # Update the repository.
    repo.add_rating(rating, user, movie)
Example #5
0
def add_comment(movie_id: int, comment_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:
        print("cant find user")
        user = User("Guest account", "Abcd1234")

    # Create comment.
    comment = make_comment(comment_text, user, movie)

    # Update the repository.
    repo.add_comment(comment)