def get_comments_for_article(article_id, repo: AbstractRepository): article = repo.get_movie(article_id) if article is None: raise NonExistentArticleException return reviews_to_dict(article.review)
def get_movie(article_id: int, repo: AbstractRepository): article = repo.get_movie(article_id) if article is None: raise NonExistentArticleException return article_to_dict(article)
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)
def get_movie(movie_rank: int, repo: AbstractRepository): movie = repo.get_movie(movie_rank) if movie is None: raise NonExistentMovieException return movie_to_dict(movie)
def add_comment(movie_rank: int, comment_text: str, 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 comment. comment = make_comment(comment_text, user, movie) # Update the repository. repo.add_comment(comment)
def add_review(article_id: int, comment_text: str, username: str, repo: AbstractRepository): # Check that the article exists. article = repo.get_movie(article_id) if article is None: raise NonExistentArticleException user = repo.get_user(username) if user is None: raise UnknownUserException # Create comment. comment = make_comment(comment_text, user, article) # Update the repository. repo.add_review(comment)