def create_movie(payload): # return 'auth implemented' # print(payload) body = request.get_json() # print(body) if not body: abort(400, {'message': 'request does not contain a valid JSON body.'}) # Extract title and release_date value from request body title = body.get('title', None) release_year = body.get('release_year', None) # print(title,release_year) # abort if one of these are missing with appropiate error message if not title: abort(422, {'message': 'no title provided.'}) if not release_year: abort(422, {'message': 'no "release_year" provided.'}) new_movie = Movies( body['title'], body['release_year'], body['duration'], body['imdb_rating'] ) new_movie.add() return jsonify({ 'success': True, 'created': new_movie.id }), 201
def add_movies(): try: data = request.get_json() title = data.get('title', None) release_date = data.get('release_date', None) movie = Movies(title=title, release_date=release_date) movie.add() return jsonify({'success': True, 'movies': [movie.format()]}), 200 except: abort(422)