def get_article(article_id: int, repo: AbstractRepository): article = repo.get_article(article_id) if article is None: raise NonExistentArticleException return article_to_dict(article)
def get_comments_for_article(article_id, repo: AbstractRepository): article = repo.get_article(article_id) if article is None: raise NonExistentArticleException return comments_to_dict(article.comments)
def add_comment(article_id: int, comment_text: str, username: str, repo: AbstractRepository): # Check that the article exists. article = repo.get_article(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_comment(comment)