Delete rankings when deleting tournament (#965)

This commit is contained in:
Erik Vroon
2024-10-27 17:59:30 +01:00
committed by GitHub
parent 27f6625547
commit e98704f4e1
4 changed files with 14 additions and 2 deletions

View File

@@ -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"

View File

@@ -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,

View File

@@ -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"
),
}

View File

@@ -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]