def single_race_endpoint(id): """GET end point to return a single race's information""" auth = Auth(app) if not auth.authenticate_request(): return auth.unauthorized_response() race = Race() single_race_query = race.get_race(id) single_race_participants = RaceParticipants( ).get_race_participants_race_id(id) if single_race_query: json = [] snails_id_list = [] for row in single_race_participants: snails_id_list.append(row.id_snail) json.append({ "id": single_race_query.id, "date": single_race_query.date, "status": single_race_query.status, "id_round": single_race_query.id_round, "id_snails": snails_id_list }) return json return { 'status': 'Failed', 'message': 'Race not found' }, status.HTTP_404_NOT_FOUND
def single_result_json(id): race = Race() race_participants = RaceParticipants() race_results = RaceResult() race_query = race.get_race(id) if race_query: json = [] snails_results_list = [] race_participants_by_id = race_participants.get_race_participants_race_id( id) for row in race_participants_by_id: race_results_snail = race_results.get_race_result(row.id) snails_results_list.append({ "id_snail": row.id_snail, "position_snail": race_results_snail.position, "time_snail": race_results_snail.time_to_finish, "DNF": race_results_snail.did_not_finish }) json.append({"id_race": int(id), "snails": snails_results_list}) return json return { 'status': 'Failed', 'message': 'Results not found' }, status.HTTP_404_NOT_FOUND