Esempio n. 1
0
def search_movie_info():
    if 'name' in request.args:
        movie_name = request.args.get('name')
        res = search_by_movie_name(movie_name)

    elif 'director' in request.args:
        director_name = request.args.get('director')
        res = search_by_movie_director(director_name)

    elif 'popularity' in request.args:
        try:
            popularity = int(request.args.get('popularity'))
        except ValueError:
            abort(422,"Value datatype mismatch")
        res = search_by_movie_popularity(popularity)

    elif 'imdb_score' in request.args:
        try:
            imdb_score = float(request.args.get('imdb_score'))
        except ValueError:
            abort(422,"Value datatype mismatch")
        res = search_by_movie_imdb_score(imdb_score)

    elif 'genre' in request.args:
        genre = request.args.get('genre')
        res = search_by_movie_genre(genre)
    
    else:
        return jsonify({"error":"missing arguments"})

    response = jsonify({"data": res})
    return response
Esempio n. 2
0
def insert_movie_info():
    movie_name = request.form.get('name')
    director_name = request.form.get('director')
    genres = request.form.getlist('genres[]')
    try:
        popularity = int(request.form.get('popularity'))
        imdb_score = float(request.form.get('imdb_score'))
    except ValueError:
        abort(422, "Value datatype mismatch")

    if movie_name and director_name:
        try:
            new_movie = insert_new_movie(movie_name, director_name, popularity,
                                         imdb_score, genres)
            if new_movie:
                response = jsonify({"message": "Movie entry inserted"})
            else:
                response = jsonify(
                    {"message": "Duplicate entry. Not inserted"})
        except ApplicationException as a:
            logger.exception(a)
            abort(422, "database error")
    else:
        response = jsonify({"error": "missing arguments"})
    return response
Esempio n. 3
0
def delete_movie_info():
    try:
        movie_name = request.form.get('name')
        res = delete_movie(movie_name)
        if res:
            response = jsonify({'message': 'Movie deleted'})
        else:
            response = jsonify({'message': 'Movie could not be deleted'})
        return response
    except ApplicationException as a:
        logger.exception(a)
        abort(500, "database error")
Esempio n. 4
0
def get_all_movies():
    movies = get_movie_list()
    response = jsonify({"data": movies}, fields_to_exclude=["id"])
    return response