def post_actor(jwt): # Gets the JSON body data = request.get_json() # print(data) # Checks that the JSON contains the complete details if 'firstname' not in data: abort(422) if 'lastname' not in data: abort(422) if 'gender' not in data: abort(422) if 'age' not in data: abort(422) # Checks that the age is an integer try: int(data.get('age')) except Exception: abort(400) # Gets each actor detail actor_firstname = data.get('firstname') actor_lastname = data.get('lastname') actor_age = int(data.get('age')) actor_gender = data.get('gender') # Checks that the details are not empty if actor_firstname is None: abort(400) if actor_lastname is None: abort(400) if actor_age is None: abort(400) if actor_gender is None: abort(400) # Initiates an instance of the Actors row new_actor = Actors( firstname=actor_firstname, lastname=actor_lastname, age=actor_age, gender=actor_gender ) try: # Insert the new actor details into the database new_actor.insert() except Exception: abort(422) actor = new_actor.details() return jsonify({ "success": True, "actor": actor }), 200
def create_actor(token): if request.get_json(): try: data = request.get_json() movie = Actors(name=data['name'], age=data['age'], gender=data['gender']) movie.insert() return jsonify({ 'success': True, 'actor': movie.details() }), 200 except: abort(500) else: abort(502)