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))
def authenticate_user(username: str, password: str, repo: AbstractRepository): authenticated = False user = repo.get_user(username) if user is not None: authenticated = check_password_hash(user.password, password) if not authenticated: raise AuthenticationException
def get_watchlist(username: str, repo: AbstractRepository): user = repo.get_user(username) if user is not None: pass else: raise UnknownUserException return user.watchlist
def add_user(username: str, password: str, repository: AbstractRepository): user = repository.get_user(username) if user is not None: raise NameNotUniqueException password_hash = generate_password_hash(password) user = User(username, password_hash) repository.add_user(user)
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)
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)
def add_user(username: str, password: str, repo: AbstractRepository): # Check that the given username is available. user = repo.get_user(username) if user is not None: raise NameNotUniqueException # Encrypt password so that the database doesn't store passwords 'in the clear'. password_hash = generate_password_hash(password) # Create and store the new User, with password encrypted. user = User(username, password_hash) repo.add_user(user)
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)
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)
def add_comment(movie_rank: int, comment_text: str, username: str, repo: AbstractRepository): # Check that the article exists. movie = repo.get_movie_by_rank(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 get_user(username: str, repository: AbstractRepository): user = repository.get_user(username) if user is None: raise UnknownUserException return user_to_dict(user)
def get_watchlist(username: str, repo: AbstractRepository): if repo.get_user(username) is None: raise UnknownUserException return repo.get_user(username).watchlist