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 get_reviews_for_movie(movie_rank, repo: AbstractRepository): movie = repo.get_movie(movie_rank) if movie is None: raise NonExistentMovieException return reviews_to_dict(movie.reviews)
def get_movies_by_genre(movie: str, repo: AbstractRepository): movie = repo.get_movie(movie.__repr__()) if movie is None: raise NonExistentMovieException return movie_to_dict(movie)
def watch_movie(username: str, title: str, year: str, repo: AbstractRepository): """ """ movie = repo.get_movie(title, int(year)) if movie: user = repo.get_user(username) if user: user.watch_movie(movie)
def remove_from_watchlist(username: str, title: str, year: str, repo: AbstractRepository): """ """ user = repo.get_user(username) if user: movie = repo.get_movie(title, int(year)) if movie: repo.remove_movie_from_watchlist(user, movie)
def add_to_watchlist(movie_rank: int, repo: AbstractRepository): # Check that the movie exists movie = repo.get_movie(movie_rank) if movie is None: raise NonExistentMovieException # Update the repository repo.add_to_watchlist(movie) add = repo.check_if_added(movie_rank)
def get_movie(title: str, year: str, repo: AbstractRepository): """ """ try: movie = repo.get_movie(title, int(year)) if not movie: raise UnknownMovieException return utils.movie_to_dict(movie) except: pass
def add_review(title: str, year: str, review_text: str, username: str, rating: int, repo: AbstractRepository): """ """ movie = repo.get_movie(title, int(year)) if movie is None: raise UnknownMovieException user = repo.get_user(username) if user is None: raise UnknownUserException review = make_review(user, movie, review_text, rating) repo.add_review(review)
def add_review(movie_rank: int, review_text: str, username: str, rating, 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 review. review = make_review(review_text, user, movie, rating) # Update the repository. repo.add_review(review)
def add_watched(user_name: str, id: int, repo: AbstractRepository): movie = repo.get_movie(id) repo.add_watched_ids(user_name, movie, id)
def get_last_movie(repo: AbstractRepository): id = repo.get_number_of_movies() movie = repo.get_movie(repo.get_number_of_movies()) return movie_to_dict(movie, id, repo)
def get_first_movie(repo: AbstractRepository): movie = repo.get_movie(1) return movie_to_dict(movie, 1, repo)