def get_movie(payload): """ Return all actors :return: """ request_dict = process_request(request) movie_id = request_dict["id"] # Convert sqlalchemy object into dict query_result = convert_sqlalchemy_todict( db.session.query(Movie).filter_by(id=movie_id).first()) return jsonify({'success': True, 'actors': query_result}, 200)
def post_movie(payload): try: request_dict = process_request(request) m1 = Movie(title=request_dict["title"]) db.session.add(m1) db.session.commit() except: db.session.rollback() db.session.close() abort(422) finally: db.session.close() return jsonify({'success': True}, 204)
def delete_movie(payload): try: request_dict = process_request(request) movie_title = request_dict["title"] db.session.query(Movie).filter_by(title=movie_title).delete() db.session.commit() except: db.session.rollback() db.session.close() abort(400) finally: db.session.close() return jsonify({'success': True}, 204)
def delete_actor(payload): request_dict = process_request(request) first_name = request_dict["first_name"] family_name = request_dict["family_name"] try: db.session.query(Actor).filter_by( first_name=first_name, family_name=family_name).delete() db.session.commit() except: db.session.rollback() db.session.close() abort(400) finally: db.session.close() return jsonify({'success': True}, 204)
def patch_movie(payload): try: request_dict = process_request(request) movie_id = request_dict["id"] title = request_dict["title"] query_result = db.session.query(Movie).filter_by(id=movie_id) if query_result.count() == 0: return jsonify({'success': False}, 404) else: query_result.title = title db.session.commit() except: db.session.rollback() db.session.close() abort(404) finally: db.session.close() return jsonify({'success': True}, 204)
def post_actor(payload): try: request_dict = process_request(request) movie_title = request_dict["movie_title"] first_name = request_dict["first_name"] family_name = request_dict["family_name"] query_result = db.session.query(Movie).filter_by( title=movie_title).first() a1 = Actor(first_name=first_name, family_name=family_name) query_result.actors.append(a1) db.session.commit() except: db.session.rollback() db.session.close() abort(422) finally: db.session.close() return jsonify({'success': True}, 204)
def patch_actor(payload): try: request_dict = process_request(request) actor_id = request_dict["id"] first_name = request_dict["first_name"] family_name = request_dict["family_name"] query_result = db.session.query(Actor).filter_by(id=actor_id) if query_result.count() == 0: return jsonify({'success': False}, 404) else: query_result.first_name = first_name query_result.family_name = family_name db.session.commit() except: db.session.rollback() db.session.close() abort(404) finally: db.session.close() return jsonify({'success': True}, 204)