示例#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)
示例#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)
示例#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)
示例#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)
示例#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)