Example #1
0
    def create_actors(payload):
        req = request.get_json()

        new_name = req.get('name')
        new_age = req.get('age')
        new_gender = req.get('gender')
        new_movie_id = req.get('movies_id')

        try:
            new_actor = Actors(name=new_name,
                               age=new_age,
                               gender=new_gender,
                               movies_id=new_movie_id)
            new_actor.insert()

            return jsonify({
                'success': True,
                'new_actor': [new_actor.format()]
            }), 200

        except BaseException:
            abort(405)

        finally:
            db.session.close()
Example #2
0
 def create_actor(jwt):
     '''
     Create an endpoint to POST a new actor,
     which will require the name, age and gender
     detals
     '''
 
     # Get the request body
     body = request.get_json()
 
     new_name = body.get('name')
     new_age = body.get('age')
     new_gender = body.get('gender')
 
     if ((new_name is None) or (new_age is None) or (new_gender is None)):
         abort(422)
 
     try:
         # create the new actor
         actor = Actors(name=new_name, age=new_age, gender=new_gender)
         actor.insert()
 
         # return the new created actor if successfully created
         return jsonify({
             'success': True,
             'actor': actor.format()
         })
 
     # raise exception for any error during deleting the actor
     except:
         db.session.rollback()
         print(sys.exc_info())
         abort(404)
    def post_actor(payload):
        body = request.get_json()

        if not ('name' in body and 'age' in body, 'gender' in body
                and 'movie' in body):
            abort(422)

        new_name = body.get('name', None)
        new_age = body.get('age', None)
        new_gender = body.get('gender', None)
        new_movie = body.get('movie', None)

        if new_name is None or new_age is None or new_gender is None:
            abort(400)

        try:
            actor = Actors(name=new_name,
                           age=new_age,
                           gender=new_gender,
                           movie_id=new_movie)
            if Actors.query.filter_by(name=actor.name).count():
                abort(409)
            actor.insert()

            return jsonify({
                'success': True,
                'actor': actor.format(),
                'total_actors': len(Actors.query.all())
            })

        except AttributeError:
            abort(422)
Example #4
0
    def update_actor(token, actor_id):

        try:
            actor = Actors.query.get(actor_id)

            body = request.get_json()

            if 'name' in body:
                new_name = body.get('name')
                setattr(actor, 'name', new_name)
            if 'age' in body:
                new_age = body.get('age')
                setattr(actor, 'age', new_age)
            if 'gender' in body:
                new_gender = body.get('gender')
                setattr(actor, 'gender', new_gender)

            Actors.update(actor)
            actor_updated = Actors.query.get(actor_id)

            return jsonify({
                'success': True,
                'actor_updated': Actors.format(actor_updated)
            })
        except Exception:
            abort(404)
Example #5
0
    def show_actors(token):

        try:
            data = Actors.query.all()
            actors = [Actors.format(actor) for actor in data]
            return jsonify({'success': True, 'actors': actors})
        except Exception:
            abort(404)
Example #6
0
 def add_actors():
     try:
         data = request.get_json()
         print(data)
         name = data.get('name', None)
         age = data.get('age', None)
         gender = data.get('gender', None)
         actor = Actors(name=name, age=age, gender=gender)
         actor.add()
         return jsonify({'success': True, 'actors': [actor.format()]}), 200
     except:
         abort(422)
Example #7
0
 def create_actor(payload):
     body = request.get_json()
     if "name" not in body:
         abort(422)
     try:
         new_actor = Actors(name=body['name'],
                            age=body['age'],
                            gender=body['gender'])
         new_actor.insert()
         actor_form = new_actor.format()
         return jsonify({'success': True, 'actor': actor_form}), 200
     except BaseException:
         abort(400)
Example #8
0
 def create_actor(headers):
     try:
         payload = request.get_json()
         actor = Actors(name=payload['name'],
                        age=payload['age'],
                        gender=payload['gender'])
         db.session.add(actor)
         db.session.commit()
         return {"success": True, "actor": actor.format()}
     except Exception as e:
         db.session.rollback()
         abort(422)
     finally:
         db.session.close()
Example #9
0
    def add_actor(jwt):
        get_input = request.get_json()

        name = get_input["name"]
        age = get_input["age"]
        gender = get_input["gender"]
        new_actor = Actors(name=name, gender=gender, age=age)
        if new_actor.name == '' or new_actor.age == '' or new_actor.gender == '':
            abort(400)
        try:
            new_actor.insert()
            return jsonify({"success": True, "actor": new_actor.format()}), 201
        except Exception as e:
            abort(422)
Example #10
0
    def post_actors(token):
        try:
            body = request.get_json()

            new_name = body.get('name', None)
            new_age = body.get('age', None)
            new_gender = body.get('gender', None)

            actor = Actors(name=new_name, age=new_age, gender=new_gender)
            actor.insert()

            actor = actor.format()

            return jsonify({'success': True, 'created': actor})
        except:
            abort(422)
Example #11
0
 def post_actors(token):
     try:
         data = request.get_json()
         name = data['name']
         age = data['age']
         gender = data['gender']
         if not name:
             abort(400)
         if not age:
             abort(400)
         if not gender:
             abort(400)
         actor = Actors(name=name, age=age, gender=gender)
         actor.insert()
         return jsonify({'success': True, 'actors': actor.format()}), 200
     except Exception:
         abort(422)
 def add_actor(payload):
     error = False
     try:
         actor_to_add = Actors(name=request.json['name'],
                               age=request.json['age'],
                               gender=request.json['gender'])
         Actors.insert(actor_to_add)
     except Exception:
         error = True
         print(sys.exc_info())
     finally:
         if error:
             abort(422)
         else:
             return jsonify({
                 'success': True,
                 'actor': [actor_to_add.format()]
             })
Example #13
0
    def add_actors(jwt):
        data = request.get_json()
        if 'name' not in data:
            abort(422)
        if 'age' not in data:
            abort(422)
        if 'gender' not in data:
            abort(422)

        try:
            new_actor = Actors(name=data.get('name'),
                               age=data.get('age'),
                               gender=data.get('gender'))
            new_actor.insert()
        except:
            abort(422)

        return jsonify({'success': True, 'actor': new_actor.format()}), 200
Example #14
0
    def create_actors(*args, **kwargs):
        try:
            body = request.get_json()
            new_name = body.get('name')
            new_age = body.get('age')
            new_gender = body.get('gender')

            actors = Actors(name=new_name, age=new_age, gender=new_gender)
            actors.insert()

            return jsonify({
                "success": True,
                "message": "Actor Successfully Added!",
                "actors": actors.format()
            })

        except AttributeError:
            abort(422)
Example #15
0
    def add_actor(token):

        try:
            body = request.get_json()
            new_name = body.get('name')
            new_age = body.get('age')
            new_gender = body.get('gender')

            actor = Actors(name=new_name, age=new_age, gender=new_gender)
            Actors.insert(actor)

            return jsonify({
                'success': True,
                'actor_added': Actors.format(actor)
            })

        except Exception:
            abort(422)
Example #16
0
    def submit_actors(jwt):

        body = request.get_json()

        new_name = body.get('name', None)
        new_age = body.get('age', None)
        new_gender = body.get('gender', None)

        if new_name is None or new_age is None or new_gender is None:
            abort(400)

        try:
            actors = Actors(name=new_name, age=new_age, gender=new_gender)
            actors.insert()

            return jsonify({'success': True, 'actors': actors.format()}), 200

        except:
            abort(422)
Example #17
0
    def new_actor(payload):
        body = request.get_json()
        name = body.get('name', None)
        age = body.get('age', None)
        gender = body.get('gender', None)

        if 'name' not in body or 'age' not in body or 'gender' not in body:
            abort(400)
        if not name or not age or not gender:
            abort(422)

        actor = Actors(name=name, age=age, gender=gender)
        actor.insert()

        return jsonify({
            'success': True,
            'actor': actor.format(),
            'total_actors': len(Actors.query.all())
        })
    def add_actor(self):
        data = request.get_json()
        name = data.get('name', None)
        age = data.get('age', None)
        gender = data.get('gender', None)

        if name is None or age is None or gender:
            abort(400)

        actor = Actors(name=name, age=age, gender=gender)

        try:
            actor.insert()
            return jsonify({
                'success': True,
                'actor': actor.format()
            }), 201
        except Exception:
            abort(500)
Example #19
0
    def post_new_actors(jwt):

        # At first get the json body from request
        body = request.get_json()

        # Then get the data needed to insert new actor (name and age and
        # gender)
        name = body.get('name', None)
        age = body.get('age', None)
        gender = body.get('gender', None).lower()

        # last step insert the new actor as new recorde in the database
        try:
            actor = Actors(name=name, age=age, gender=gender)
            actor.insert()

            return jsonify({"success": True, "new actor": actor.format()})

        except BaseException:
            abort(422)
Example #20
0
    def creat_actor(token):

        form = request.get_json()

        name = form.get('name')
        age = form.get('age')
        gender = form.get('gender')

        if name is None or age is None or gender is None:
            abort(404)

        try:

            actor = Actors(name=name, age=age, gender=gender)
            actor.insert()
            all_actors = Actors.query.all()
            actors = [actor.format() for actor in all_actors]
            return jsonify({"success": True, "actors": actors}), 200
        except:
            abort(422)
Example #21
0
    def create_actor():
        """
        Required: name, gender, age
        Optional: movies
        :return:
        """
        try:
            required_props = [
                'name',
                'gender',
                'age'
            ]

            optional_props = [
                'movies'
            ]

            actor_data = {}
            for prop in required_props:
                actor_data[prop] = request.get_json()[prop]

            for prop in optional_props:
                if prop in request.get_json():
                    actor_data[prop] = request.get_json()[prop]

            actor_data = validate_actor(**actor_data)

            actor = Actors(**actor_data)
            actor.insert()
            response = {
                'success': True,
                'actors': [actor.format()]
            }
        except UnprocessableEntity:
            raise
        except Exception:
            print(sys.exc_info())
            raise BadRequest

        return jsonify(response)
Example #22
0
    def add_actor(jwt):
        '''
        POST endpoint to craete new actor which require actor name, age and gender
        it require the 'post:actor' permission
        '''
        body = request.get_json()

        name = body.get('name')
        age = body.get('age')
        gender = body.get('gender')

        if name == '':
            abort(422)

        try:
            actor = Actors(name=name, age=age, gender=gender)
            actor.insert()

            return jsonify({'success': True, 'created': actor.format()})

        except BaseException:
            abort(422)
Example #23
0
 def new_actor(payload):
   body = request.get_json()
   
   # if no form data
   if body is None:
     abort(404)
     
   name = body.get('name', None)
   age = body.get('age', None)
   gender = body.get('gender', None)
   
   try:
     actor = Actors(name=name, age=age, gender=gender)
     actor.insert()
     
     return jsonify({
       'success': True,
       'actor': actor.format(),
       }), 200
     
   except Exception as e:
     print(e)
     abort(422)
Example #24
0
    def new_actor(payload):
        """
        Add an Actor here
        :param payload:
        :return:
        """
        form = request.get_json(force=True)

        if Actors.query.filter_by(name=form['name']).first() is not None:
            abort(500, "Actor '{}' already exists...".format(form['name']))

        try:
            new_actor = Actors(name=form['name'],
                               gender=form['gender'],
                               age=form['age'],
                               joined_in=form['joined_in'],
                               agent_id=form['agent_id'])
            new_actor.insert()
        except Exception as e:
            print(e)
            abort(500, e)

        return jsonify({'actor': [new_actor.format()]})
Example #25
0
 def get_actors(payload):
     data = Actors.query.all()
     fromatted_actors = [Actors.format() for Actors in data]
     return jsonify({"Actors": fromatted_actors})