Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions app/modules/sport_competition/cruds_sport_competition.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ async def add_edition(
edition: schemas_sport_competition.CompetitionEdition,
db: AsyncSession,
):
db.add(models_sport_competition.CompetitionEdition(**edition.model_dump()))
db.add(
models_sport_competition.CompetitionEdition(
id=edition.id,
name=edition.name,
year=edition.year,
start_date=edition.start_date,
end_date=edition.end_date,
active=edition.active,
inscription_enabled=edition.inscription_enabled,
),
)
await db.flush()


Expand Down Expand Up @@ -1428,7 +1438,16 @@ async def add_sport(
sport: schemas_sport_competition.Sport,
db: AsyncSession,
):
db.add(models_sport_competition.Sport(**sport.model_dump()))
db.add(
models_sport_competition.Sport(
id=sport.id,
name=sport.name,
team_size=sport.team_size,
substitute_max=sport.substitute_max,
sport_category=sport.sport_category,
active=sport.active,
),
)
await db.flush()


Expand Down Expand Up @@ -1530,7 +1549,17 @@ async def add_team(
team: schemas_sport_competition.Team,
db: AsyncSession,
):
db.add(models_sport_competition.CompetitionTeam(**team.model_dump()))
db.add(
models_sport_competition.CompetitionTeam(
id=team.id,
name=team.name,
school_id=team.school_id,
sport_id=team.sport_id,
edition_id=team.edition_id,
captain_id=team.captain_id,
created_at=team.created_at,
),
)
await db.flush()


Expand Down Expand Up @@ -1851,7 +1880,22 @@ async def add_match(
match: schemas_sport_competition.Match,
db: AsyncSession,
):
db.add(models_sport_competition.Match(**match.model_dump()))
db.add(
models_sport_competition.Match(
id=match.id,
sport_id=match.sport_id,
edition_id=match.edition_id,
name=match.name,
team1_id=match.team1_id,
team2_id=match.team2_id,
date=match.date,
location_id=match.location_id,
score_team1=match.score_team1,
score_team2=match.score_team2,
winner_id=match.winner_id,
ended=match.ended,
),
)
await db.flush()


Expand Down
3 changes: 2 additions & 1 deletion app/modules/sport_competition/endpoints_sport_competition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3148,6 +3148,7 @@ async def create_match(
winner_id=None,
score_team1=None,
score_team2=None,
ended=False,
)
await cruds_sport_competition.add_match(match, db)
return match
Expand Down Expand Up @@ -4035,7 +4036,7 @@ async def create_user_purchase(
user_id=user_id,
product_variant_id=purchase.product_variant_id,
edition_id=edition.id,
validated=False,
validated=(product_variant.price == 0 and competition_user.validated),
quantity=purchase.quantity,
purchased_on=datetime.now(UTC),
)
Expand Down
1 change: 1 addition & 0 deletions app/modules/sport_competition/models_sport_competition.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class Match(Base):
score_team1: Mapped[int | None]
score_team2: Mapped[int | None]
winner_id: Mapped[UUID | None] = mapped_column(ForeignKey("competition_team.id"))
ended: Mapped[bool]

team1: Mapped[CompetitionTeam] = relationship(
"CompetitionTeam",
Expand Down
2 changes: 2 additions & 0 deletions app/modules/sport_competition/schemas_sport_competition.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class MatchBase(BaseModel):
score_team1: int | None = None
score_team2: int | None = None
winner_id: UUID | None = None
ended: bool


class Match(MatchBase):
Expand All @@ -327,6 +328,7 @@ class MatchEdit(BaseModel):
score_team1: int | None = None
score_team2: int | None = None
winner_id: UUID | None = None
ended: bool | None = None


class TeamSportResultBase(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions app/modules/sport_competition/utils/schemas_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def match_model_to_schema(
score_team1=match.score_team1,
score_team2=match.score_team2,
winner_id=match.winner_id,
ended=match.ended,
team1=schemas_sport_competition.Team(
name=match.team1.name,
school_id=match.team1.school_id,
Expand Down
58 changes: 58 additions & 0 deletions migrations/versions/58-ended_matches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""empty message

Create Date: 2026-03-16 19:11:58.596543
"""

from collections.abc import Sequence
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pytest_alembic import MigrationContext

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "e58ffcd6b9eb"
down_revision: str | None = "e269727ac79f"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"competition_match",
sa.Column("ended", sa.Boolean(), nullable=False, server_default=sa.false()),
)
conn = op.get_bind()
conn.execute(
sa.text(
"""
UPDATE competition_match
SET ended = true
WHERE winner_id IS NOT NULL
""",
),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("competition_match", "ended")
# ### end Alembic commands ###


def pre_test_upgrade(
alembic_runner: "MigrationContext",
alembic_connection: sa.Connection,
) -> None:
pass


def test_upgrade(
alembic_runner: "MigrationContext",
alembic_connection: sa.Connection,
) -> None:
pass
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = [{ name = "AEECL ECLAIR" }]

# Hyperion follows Semantic Versioning
# https://semver.org/
version = "5.3.4"
version = "5.3.5"
requires-python = ">= 3.12, < 3.15"

license = "MIT"
Expand Down
14 changes: 13 additions & 1 deletion tests/modules/sport_competition/test_sport_inscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ async def init_objects() -> None:
score_team1=None,
score_team2=None,
winner_id=None,
ended=False,
)
await add_object_to_db(match1)

Expand Down Expand Up @@ -754,7 +755,7 @@ async def test_patch_sport_as_admin(
"team_size": 6,
"substitute_max": 3,
"active": True,
"sport_category": SportCategory.feminine.value,
"sport_category": None,
},
)
assert response.status_code == 204, response.json()
Expand All @@ -771,6 +772,9 @@ async def test_patch_sport_as_admin(
)
assert updated_sport_check is not None
assert updated_sport_check["name"] == "Updated Sport"
assert updated_sport_check["team_size"] == 6
assert updated_sport_check["substitute_max"] == 3
assert updated_sport_check["sport_category"] is None


async def test_patch_sport_with_duplicate_name(
Expand Down Expand Up @@ -2797,6 +2801,7 @@ async def test_create_match_as_random(
team2_id=team2.id,
location_id=location.id,
date=datetime.now(UTC),
ended=False,
)
response = client.post(
f"/competition/matches/sports/{sport_with_team.id}",
Expand Down Expand Up @@ -2827,6 +2832,7 @@ async def test_create_match_as_admin(
team2_id=team2.id,
location_id=location.id,
date=datetime(2024, 6, 15, 15, 0, 0, tzinfo=UTC),
ended=False,
)
response = client.post(
f"/competition/matches/sports/{sport_with_team.id}",
Expand Down Expand Up @@ -2886,6 +2892,7 @@ async def test_patch_match_as_admin(
"score_team1": 3,
"score_team2": 2,
"winner_id": str(team1.id),
"ended": True,
},
)
assert response.status_code == 204, response.json()
Expand All @@ -2905,6 +2912,7 @@ async def test_patch_match_as_admin(
assert updated_match_check["score_team1"] == 3
assert updated_match_check["score_team2"] == 2
assert updated_match_check["winner_id"] == str(team1.id)
assert updated_match_check["ended"] is True


async def test_edit_match_as_sport_manager(
Expand All @@ -2918,6 +2926,7 @@ async def test_edit_match_as_sport_manager(
"score_team1": 1,
"score_team2": 1,
"winner_id": None,
"ended": True,
},
)
assert response.status_code == 204, response.json()
Expand All @@ -2937,6 +2946,7 @@ async def test_edit_match_as_sport_manager(
assert updated_match_check["score_team1"] == 1
assert updated_match_check["score_team2"] == 1
assert updated_match_check["winner_id"] is None
assert updated_match_check["ended"] is True


async def test_delete_match_as_random(
Expand Down Expand Up @@ -2976,6 +2986,7 @@ async def test_delete_match_as_admin(
score_team1=None,
score_team2=None,
winner_id=None,
ended=False,
)
await add_object_to_db(new_match)
response = client.delete(
Expand Down Expand Up @@ -3012,6 +3023,7 @@ async def test_delete_match_as_sport_manager(
score_team1=None,
score_team2=None,
winner_id=None,
ended=False,
)
await add_object_to_db(new_match)
response = client.delete(
Expand Down
Loading