From e98704f4e13b8f1927e25e52b3af04868e9770a7 Mon Sep 17 00:00:00 2001 From: Erik Vroon Date: Sun, 27 Oct 2024 17:59:30 +0100 Subject: [PATCH] Delete rankings when deleting tournament (#965) --- backend/Pipfile | 2 +- backend/bracket/routes/tournaments.py | 9 ++++++++- backend/bracket/utils/errors.py | 4 ++++ backend/pyproject.toml | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/Pipfile b/backend/Pipfile index 069d66bb..abcd9414 100644 --- a/backend/Pipfile +++ b/backend/Pipfile @@ -12,7 +12,7 @@ alembic = ">=1.13.1" bcrypt = "4.2.0" click = ">=8.1.3" databases = {extras = ["asyncpg"], version = "<=0.8.0"} -fastapi = ">=0.88.0" +fastapi = "0.114.0" fastapi-cache2 = ">=0.2.0" fastapi-sso = ">=0.6.4" gunicorn = ">=20.1.0" diff --git a/backend/bracket/routes/tournaments.py b/backend/bracket/routes/tournaments.py index f9cb2b63..ad8f9eaa 100644 --- a/backend/bracket/routes/tournaments.py +++ b/backend/bracket/routes/tournaments.py @@ -23,7 +23,11 @@ from bracket.routes.auth import ( ) from bracket.routes.models import SuccessResponse, TournamentResponse, TournamentsResponse from bracket.schema import tournaments -from bracket.sql.rankings import sql_create_ranking +from bracket.sql.rankings import ( + get_all_rankings_in_tournament, + sql_create_ranking, + sql_delete_ranking, +) from bracket.sql.tournaments import ( sql_create_tournament, sql_delete_tournament, @@ -107,6 +111,9 @@ async def update_tournament_by_id( async def delete_tournament( tournament_id: TournamentId, _: UserPublic = Depends(user_authenticated_for_tournament) ) -> SuccessResponse: + for ranking in await get_all_rankings_in_tournament(tournament_id): + await sql_delete_ranking(tournament_id, ranking.id) + with check_foreign_key_violation( { ForeignKey.stages_tournament_id_fkey, diff --git a/backend/bracket/utils/errors.py b/backend/bracket/utils/errors.py index 70e50a3e..b0120b8b 100644 --- a/backend/bracket/utils/errors.py +++ b/backend/bracket/utils/errors.py @@ -25,6 +25,7 @@ class ForeignKey(EnumAutoStr): stages_tournament_id_fkey = auto() teams_tournament_id_fkey = auto() tournaments_club_id_fkey = auto() + rankings_tournament_id_fkey = auto() unique_index_violation_error_lookup = { @@ -48,6 +49,9 @@ foreign_key_violation_error_lookup = { ForeignKey.stages_tournament_id_fkey: "This tournament still has stages, delete those first", ForeignKey.teams_tournament_id_fkey: "This tournament still has teams, delete those first", ForeignKey.tournaments_club_id_fkey: "This club still has tournaments, delete those first", + ForeignKey.rankings_tournament_id_fkey: ( + "This tournament still has rankings, delete those first" + ), } diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 0ece8731..19d24b54 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -12,6 +12,7 @@ filterwarnings = [ 'ignore:.*:pytest.PytestDeprecationWarning', 'ignore:.*pytest-asyncio detected an unclosed event loop.*:DeprecationWarning', 'ignore:.*The event_loop fixture provided by pytest-asyncio has been redefined.*:DeprecationWarning', + 'ignore:.*Please use `import python_multipart` instead.*:PendingDeprecationWarning', ] [tool.mypy]