def get_movie_by_uuid(uuid): movie = Movie.get_by_uuid(uuid) if movie is None: return IkiruJsonResponse(message='Movie does not exist.', status_code=404) m = movie.as_dict() m['genres'] = [g.name for g in movie.genres] return IkiruJsonResponse(m)
def rent_movie(parser): args = parser.parse_args() movie = Movie.get_by_uuid(args['movie_uuid']) if movie is None: return IkiruJsonResponse(message='Invalid movie identifier', status_code=404) rental = Rental(user_id=g.user.id, movie_id=movie.id) db.session.add(rental) db.session.commit() db.session.refresh(rental) return IkiruJsonResponse( payload=rental, message=f'Movie `{movie.title}` rented successfully.')
def get_movie_rentals(uuid): movie = Movie.get_by_uuid(uuid) if movie is None: return IkiruJsonResponse(message='Movie does not exist.', status_code=404) return IkiruJsonResponse(movie.rentals)