Ejemplo n.º 1
0
def edit_movie(id):
    movie = Movies.query.get(id)
    if movie is None:
        movie = Movies.from_json(request.json)
    movie.director = request.json.get('director', movie.director)
    movie.year = request.json.get('year', movie.year)
    movie.title = request.json.get('title', movie.title)
    movie.length = request.json.get('length', movie.length)
    movie.rating = request.json.get('rating', movie.rating)
    db_session.add(movie)
    db_session.commit()
    return (jsonify(movie.to_json()), 200, {
        'Location': url_for('api.get_movie', id=movie.id, _external=True)
    })
Ejemplo n.º 2
0
def new_post():
    movie = Movies.from_json(request.json)

    if movie.year > 2100:
        abort(
            make_response(
                jsonify({
                    "status": 400,
                    "reason": "Field 'year' should be less then 2100"
                }), 400))
    if movie.title is None:
        abort(
            make_response(
                jsonify({
                    "status": 400,
                    "reason": "Field 'title' is required"
                }), 400))
    db_session.add(movie)
    db_session.commit()
    return (jsonify(movie.to_json()), 200, {
        'Location': url_for('api.get_movie', id=movie.id, _external=True)
    })