Ejemplo n.º 1
0
    def new_movie(jwt):
        body = request.get_json(force=True)

        if not ('title' in body and 'release_date' in body):
            abort(422)
        title = body.get('title')
        release_date = body.get('release_date')

        try:
            movie = Movies(title=title, release_date=release_date)
            movie.create()

            return jsonify({'success': True, 'movies': [movie.serialize]})

        except:
            abort(422)
Ejemplo n.º 2
0
def create_movie():
    if not request.is_json:
        return 'You should send JSON data', 400
    data = request.json
    if type(data) == list:
        return 'You should send JSON dictionary', 400
    if 'title' not in data:
        return '"Title" field is required', 400
    title = data.get('title')
    year = data.get('year')
    movie = Movies.create(title=title, year=year)

    return jsonify(movie.to_dict()), 201