def add_player(): new_player = request.form['new_player'] # name = player_repository.select(new_player) player = Player(new_player) player_repository.save(player) return redirect('/players')
def create_player(): name = request.form["name"] player_info = request.form["player_info"] goals_scored = request.form["goals_scored"] new_player = Player(name, player_info, goals_scored) player_repository.save(new_player) return redirect("/clubs/players")
def register_player(request: RegisterPlayerRequest) -> Player: if player_repository.find_by_name(request.name): raise HTTPException(status_code=400, detail='Name already taken') player = Player(name=request.name, elo=request.elo) player_repository.save(player) return player
def register_player(): post_data = request.get_json() # Check if player already exists player = player_repository.select_by_email(post_data.get('email')) if not player: try: # New player player = Player( email=post_data.get('email'), password=post_data.get('password'), first_name=post_data.get('firstName'), last_name=post_data.get('lastName'), team_name=post_data.get('teamName') ) player_repository.save(player) setup_new_player(player) auth_token = player.encode_jwt(player.id) response = { 'status': 'success', 'message': 'Successfully registered.', 'auth_token': auth_token } return make_response(jsonify(response)), 201 except Exception as e: response = { 'status': 'fail', 'message': 'Something went wrong. Please try again.' } return make_response(jsonify(response)), 401 else: response = { 'status': 'fail', 'message': 'User already exists. Please log in.' } return make_response(jsonify(response)), 202
from models.player import Player from models.tournament import Tournament import repositories.game_repository as game_repository import repositories.player_repository as player_repository import repositories.tournament_repository as tournament_repository # Every time console starts, all entries, that were saved, are deleted tournament_repository.delete_all() player_repository.delete_all() game_repository.delete_all() # starts adding entries player1 = Player('Charo') player_repository.save(player1) player2 = Player('Neil') player_repository.save(player2) player3 = Player('Joe') player_repository.save(player3) game1 = Game(1, player1, player2) game_repository.save(game1) game2 = Game(2, player1, player3) game_repository.save(game2) game3 = Game(3, player3, player2) game_repository.save(game3)
team_repository.save(team_4) team_5 = Team("Clydesdale Hockey Club Mens", "Prosperity Financial Solutions") team_repository.save(team_5) team_6 = Team("Uddingston Hockey Club Mens", "Aratac Hockey") team_repository.save(team_6) team_7 = Team("Edinburgh University", "Deans Civil Engineering") team_repository.save(team_7) team_8 = Team("Kelburne Hockey Club Mens", "Cala Properties") team_repository.save(team_8) team_9 = Team("Dundee Wanderers Hockey Club Mens", "MJ Ventilation") team_repository.save(team_9) team_10 = Team("The Watsonian Hockey Club Men", "Avenir Analytics") team_repository.save(team_10) player_1 = Player("Kieran Lamb", "Centre Back", team_1) player_repository.save(player_1) player_2 = Player("Aidan Lamb", "Left back", team_2) player_repository.save(player_2) player_3 = Player("Gwen", "Centre mid", team_1) player_repository.save(player_3) player_4 = Player("Stuart", "GK", team_1) player_repository.save(player_4) game_1 = Game("12/07/95", "Peffermill", team_1, team_2, 1, 1) game_repository.save(game_1) game_2 = Game("25/12/2020", "Inveralmond", team_3, team_1, 2, 0) game_repository.save(game_2)