示例#1
0
    def put(self):
        token = request.headers.get('Authorization')
        if not token:
            abort(403, error="Unauthorized Access (no token)")
        privilege_handler = PrivilegeHandler(token)
        if not privilege_handler.schedule_privileges(
        ) and not privilege_handler.update_score():
            abort(403, error="Unauthorized Access (invalid permissions)")

        parser = reqparse.RequestParser()
        parser.add_argument('gameID', type=int, required=True)
        parser.add_argument('leagueID', type=int, required=True)
        parser.add_argument('homeTeamID', type=int, required=True)
        parser.add_argument('awayTeamID', type=int, required=True)
        parser.add_argument('refereeID', type=int)
        parser.add_argument('gameTime', type=str)
        parser.add_argument('fieldName', type=str)
        parser.add_argument('status', type=str)
        args = parser.parse_args()

        game_id = args['gameID']
        league_id = args['leagueID']
        home_team_id = args['homeTeamID']
        away_team_id = args['awayTeamID']
        referee_id = args['refereeID']
        game_time = args['gameTime']
        field_name = args['fieldName']
        status = args['status']
        db = DatabaseConnector()
        db.cursor.callproc('update_game', [
            game_id, league_id, home_team_id, away_team_id, referee_id,
            game_time, field_name, status
        ])

        db.conn.commit()
        return 200
示例#2
0
    def put(self, game_id):
        """
        Adds a roster to the database.

        :Input:  JSON object representing the game-roster

            .. code-block:: javascript

                'roster': List<Player>{
                    "playerID": int,
                    "teamID": int,
                    "number": int,
                    "goals": int,
                    "cleanSheet": int,
                    "yellowCards": int,
                    "redCards": int
                }


        Success gives status code 201

        """

        token = request.headers.get('Authorization')
        if not token:
            abort(403, error="Unauthorized Access (no token)")
        privilege_handler = PrivilegeHandler(token)
        if not privilege_handler.assign_player(
        ) and not privilege_handler.update_score():
            abort(403, error="Unauthorized Access (invalid permissions)")

        roster = request.get_json()['roster']

        # creating new league in the database
        db_connector = DatabaseConnector()
        db_connector.cursor.callproc('get_game_team_lineup', [int(game_id)])
        team_lineup = db_connector.cursor.fetchall()[0]

        gameMembers = []
        conflicts = []
        count = 0
        for player in roster:
            player_id = player['playerID']
            team_id = player['teamID']
            number = player['number']
            goals = player['goals']
            clean_sheet = player['cleanSheet']
            yellow_cards = player['yellowCards']
            red_cards = player['redCards']

            gameMember_data = {
                'gameID': int(game_id),
                'playerID': player_id,
                'teamID': team_id,
                'number': number,
                'goals': goals,
                'cleanSheet': clean_sheet,
                'yellowCards': yellow_cards,
                'redCards': red_cards
            }

            if team_id != team_lineup[0] and team_id != team_lineup[1]:
                conflicts.append("Team " + str(team_id) +
                                 " is not playing in game " + str(game_id))
            else:
                try:
                    db_connector.cursor.callproc('update_game_member', [
                        int(game_id), player_id, team_id, number, goals,
                        clean_sheet, yellow_cards, red_cards
                    ])
                    gameMembers.append(gameMember_data)
                except Exception as e:
                    conflicts.append(str(e))

            count += 1

        db_connector.conn.commit()
        db_connector.cursor.close()

        return {'conflicts': conflicts, 'gameMembers': gameMembers}, 201