def add_user(username: str, password: str, repo: AbstractRepository): user = repo.get_user(username.lower()) if user is not None: raise NameNotUniqueException hashed_password = generate_password_hash(password) user = User(username, hashed_password) repo.add_user(user)
def validate_user(username: str, password: str, repo: AbstractRepository): validated = False user = repo.get_user(username.lower()) if user is not None: validated = check_password_hash(user.password, password) if not validated: raise ValidationException
def get_movies(id_list, repo: AbstractRepository): movies = repo.get_movies_for_browse(id_list) return movies
def get_ids_of_movies(repo: AbstractRepository): id_list = repo.get_ids_of_movies() return id_list
def get_user(username: str, repo: AbstractRepository): user = repo.get_user(username.lower()) if user is None: raise UnknownUserException return user
def get_movies_by_actor(movie_ids: list, repo: AbstractRepository): movies = repo.get_movies_by_actor(movie_ids) return movies
def get_movies_ids_by_director(director, repo: AbstractRepository): movie_ids = repo.get_movies_ids_by_director(director) return movie_ids
def get_movies_ids_by_genre(genre, repo: AbstractRepository): movie_ids = repo.get_movies_ids_by_genre(genre) return movie_ids
def get_movies_ids_by_title(title, repo: AbstractRepository): movie_ids = repo.get_movies_ids_by_title(title) return movie_ids