Esempio n. 1
0
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)
Esempio n. 2
0
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
Esempio n. 3
0
def add_review(movie: Movie, comment_text: str, rating: int, username: str,
               repo: AbstractRepository):
    # Check that the movie exists.
    movie = repo.get_movie(movie)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)

    if user is None:
        raise UnknownUserException

    # Create comment.
    comment = Review(movie, comment_text, rating)
    comment.user = user
    user.add_review(comment)
    movie.add_review(comment)

    # Update the repository.
    repo.add_review(comment)
Esempio n. 4
0
def get_user(username: str, repo: AbstractRepository):
    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    return user_to_dict(user)
Esempio n. 5
0
def get_movie(repo: AbstractRepository, movie):
    if movie is None:
        raise NonExistentMovieException
    movie = repo.get_movie_by_title(movie)
    return movie
Esempio n. 6
0
def get_10_movies_genre(repo: AbstractRepository, genre):
    movies = repo.get_10_movies_genre(genre)
    return movies
Esempio n. 7
0
def get_genres(repo: AbstractRepository):
    genres = repo.get_genres()
    return genres
Esempio n. 8
0
def get_ten_movies(repo: AbstractRepository):
    movies = repo.get_10_movies()
    return movies
Esempio n. 9
0
def get_all_movies_genre(repo: AbstractRepository, genre):
    if genre is None:
        raise NonExistentGenreException
    movies = repo.get_all_movies_genre(genre)
    return movies
Esempio n. 10
0
def get_movies_by_actor(repo: AbstractRepository, title):
    if title is None:
        raise NonExistentActorException
    movies = repo.get_movies_by_actor(title)
    return movies