def join_player_league():
    player_id = join_player_league.user_id
    post_data = request.get_json()
    if not isinstance(player_id, str):
        league = league_repository.select_by_join_code(
            post_data.get('join_code'))
        if league is not None:
            try:
                active_player = player_repository.select(player_id)
                player_league = PlayerLeague(league, active_player)
                player_league_repository.save(player_league)

                response = {
                    'status':
                    'success',
                    'message':
                    'Successfully joined the ' + league.name + ' league!'
                }

                return make_response(jsonify(response)), 200
            except Exception as e:
                response = {'status': 'fail', 'message': e}
                return make_response(jsonify(response)), 200
        else:
            response = {
                'status': 'fail',
                'message': 'League could not be found.'
            }
            return make_response(jsonify(response)), 200
    else:
        response = {'status': 'fail', 'message': player_id}
        return make_response(jsonify(response)), 401
Ejemplo n.º 2
0
def select_all():
    player_leagues = []

    sql = "SELECT * FROM player_leagues"
    results = run_sql(sql)

    for row in results:
        player = player_repository.select(row['player_id'])
        league = league_repository.select(row['league_id'])
        player_league = PlayerLeague(league, player, row['id'])
        player_leagues.append(player_league)
    return player_leagues
Ejemplo n.º 3
0
def select(id):
    player_league = None

    sql = "SELECT * FROM player_leagues WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        player = player_repository.select(result['player_id'])
        league = league_repository.select(result['league_id'])
        player_league = PlayerLeague(league, player, result['id'])
    return player_league
def new_player_league():
    player_id = new_player_league.user_id
    post_data = request.get_json()
    if not isinstance(player_id, str):
        try:
            active_player = player_repository.select(player_id)
            league = League(post_data.get('name'))
            league_repository.save(league)
            player_league = PlayerLeague(league, active_player)
            player_league_repository.save(player_league)

            response = {
                'status': 'success',
                'message': league.name + ' code: ' + league.join_code
            }

            return make_response(jsonify(response)), 201
        except Exception as e:
            response = {'status': 'fail', 'message': e}
            return make_response(jsonify(response)), 200
    else:
        response = {'status': 'fail', 'message': player_id}
        return make_response(jsonify(response)), 401
Ejemplo n.º 5
0
def add_to_overall_league(player):
    overall_league = league_repository.select(1)
    player_league_repository.save(PlayerLeague(overall_league, player))
Ejemplo n.º 6
0
        if len(row["Round Number"]) == 1:
            team_1 = team_repository.select_by_name(row["Home Team"])
            team_2 = team_repository.select_by_name(row["Away Team"])
            match = Match(row["Round Number"], date, row["Location"],
                          row["Group"], team_1, team_2)
            match_repository.save(match)

csv_file.close()

# Leagues
league_1 = League("Overall")
league_1.join_code = "0000-0000"
league_repository.save(league_1)

# Player Leagues
player_league_1 = PlayerLeague(league_1, player_1)
player_league_repository.save(player_league_1)
player_league_2 = PlayerLeague(league_1, player_2)
player_league_repository.save(player_league_2)

# Player Teams
for team in team_repository.select_all():
    player_team_repository.save(PlayerTeam(player_1, team))

# Player Groups
for group in group_repository.select_all():
    player_teams = []
    for team in group.teams:
        player_teams.append(
            player_team_repository.select_by_player_and_team(player_1, team))
    player_group_repository.save(
    def setUp(self):
        self.player_1 = Player("*****@*****.**", "password1", "John", "Smith",
                               "Hopp Suisse")
        self.league_1 = League("Wilton Wanderers", "1234-5678")

        self.player_league_1 = PlayerLeague(self.league_1, self.player_1)