Example #1
0
 def create_movie(token):
     if request.get_json():
         try:
             data = request.get_json()
             movie = Movies(title=data['title'],
                            release_date=data['release_date'])
             movie.insert()
             return jsonify({
                 'success': True,
                 'movie': movie.details()
             }), 200
         except:
             abort(500)
     else:
         abort(502)
Example #2
0
def post_movie(jwt):
    # Gets the JSON body
    data = request.get_json()
    # print(data)

    # Checks that the JSON contains the complete details
    if 'title' not in data:
        abort(422)

    # Gets each movie detail
    movie_title = data.get('title')
    movie_release_date = None
    movie_description = None

    if 'release_date' in data:
        movie_release_date = data.get('release_date')

    if 'description' in data:
        movie_description = data.get('description')

    # Checks that the movie title is not empty
    if movie_title is None:
        abort(400)

    # Initiates an instance of the Movies row
    new_movie = Movies(title=movie_title,
                       release_date=movie_release_date,
                       description=movie_description)
    try:
        # Insert the new movie details into the database
        new_movie.insert()
    except Exception:
        abort(422)

    movie = new_movie.details()

    return jsonify({"success": True, "movie": movie}), 200