def delete(self, name): data = Player.parser.parse_args() team = TeamModel.find_by_name(data['team_name']) if team is None: return {"message": "Team does not exist"} player = PlayerModel.find_player_in_team(name, team.id, data['back_number']) if player: player.delete_from_db() return {"message": "Player deleted"}
def get(self, team_name=None, division=None): if team_name is None and division is None: players = PlayerModel.query.all() else: team = TeamModel.find_by_name(team_name) if team: players = PlayerModel.find_by_team_id(team.id) else: players = PlayerModel.find_by_division(division) return {"players": [player.json() for player in players]}
def put(self, name): data = Team.parser.parse_args() team = TeamModel.find_by_name(name) if team is None: team = TeamModel(name, data['division']) else: team.division = data['division'] team.save_to_db() return team.json()
def post(self, name): data = Player.parser.parse_args() team = TeamModel.find_by_name(data['team_name']) if team is None: return {"message": "Team does not exist"} if PlayerModel.find_by_back_number_in_team(data['back_number'], team.id): return {"message": "Back number is already taken."} player = PlayerModel(name, data['back_number'], team.id) player.save_to_db() return player.json()
def post(self, name): if TeamModel.find_by_name(name): return { 'message': "A team with name '{}' already exists.".format(name) }, 400 team = TeamModel(name) try: team.save_to_db() except: return {"message": "An error occurred creating the team."}, 500 return team.json(), 201
def delete(self, name): # data = Team.parser.parse_args() # # if data['division'] is None: # return {"division": "This field can not be blank"} # # team = TeamModel.find_by_name_division(name,data['division']) # if team: # team.delete_from_db() # return {"message": "Team deleted"} team = TeamModel.find_by_name(name) if team: team.delete_from_db() return {"message": "Team deleted"}
def post(self, name, division=None): data = Team.parser.parse_args() if TeamModel.find_by_name(name): return {"message": "{} already exists".format(name)} team = TeamModel(name, data['division']) try: team.save_to_db() except: return { "message": "An error occured while creating the team." }, 500 return team.json()
def get(self, name): ''' data = Team.parser.parse_args() if data['division']: team = TeamModel.find_by_name_division(name, data['division']) if team: return {"team": team.json()} else: teams = TeamModel.find_by_name(name) if teams.count() > 0: return {"teams": [team.json() for team in teams]} return {"message" : "Team not found"}, 404 ''' team = TeamModel.find_by_name(name) if team: return {"teams": team.json()} return {"message": "Team not found"}, 404
def put(self, name): data = Player.parser.parse_args() team = TeamModel.find_by_name(data['team_name']) if team is None: return {"message": "Team does not exist"} if PlayerModel.find_by_back_number_in_team(data['new_back_number'], team.id): return {"message": "Back number is already taken."} player = PlayerModel.find_player_in_team(name, team.id, data['back_number']) if player is None: return {"message": "Player doesn not exist"} else: if data['new_back_number'] is None: return {"message": "New Back Number is missing"} player.back_number = data['new_back_number'] player.save_to_db() return player.json()
def get(self, name): team = TeamModel.find_by_name(name) if team: return team.json() return {'message': 'Store not found'}, 404
def delete(self, name): team = TeamModel.find_by_name(name) if team: team.delete_from_db() return {'message': 'Team deleted'}