Beispiel #1
0
  def create_player_submission(jwt):
      error = False
      body = {}
      try:
          body = request.get_json()
          first_name = body['first_name']
          last_name = body['last_name']
          image = body['image']
          team_id = body['team_id']
          number = body['number']
          position = body['position']

          player = Player(first_name=first_name, last_name=last_name, image=image, number=number, team_id=team_id, position=position)
          player.insert()

      except():
          error = True
      if error:
          abort(500)
      else:
          playersarray = []
          playersarray.append(player.format())
          return jsonify ({
            'success': True,
            'created_player': playersarray
            })
Beispiel #2
0
    def get_or_create_player():
        data = request.get_json()

        player = Player.query.filter(
            Player.name == data['player_name']).one_or_none()

        if not player:
            player = Player(data['player_name'])
            player.insert()

        return jsonify({'success': True, 'player': player.format()})
Beispiel #3
0
    def create_player(payload):
        try:
            body = request.get_json()

            new_name = body.get('name', None)
            new_skill = body.get('skill', None)

            player = Player(name=new_name, skill=new_skill)
            player.insert()

            return jsonify({'success': True, 'player': player.format()})
        except:
            abort(422)
Beispiel #4
0
    def post_player(jwt):

        try:
            player_data = request.get_json()

            first_name = player_data.get('first_name')
            last_name = player_data.get('last_name')
            player_number = player_data.get('player_number')
            team = player_data.get('team')
            mpg = player_data.get('mpg')
            ppg = player_data.get('ppg')
            rpg = player_data.get('rpg')
            apg = player_data.get('apg')
            team_id = player_data.get('team_id')

            player = Player(
                first_name=first_name,
                last_name=last_name,
                player_number=player_number,
                team=team,
                mpg=mpg,
                ppg=ppg,
                rpg=rpg,
                apg=apg,
                team_id=team_id
            )

            player.insert()

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

        except Exception:
            print(sys.exc_info())
            abort(400)