Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sport result #597

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions app/core/groups/groups_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class GroupType(str, Enum):
# Module related groups
amap = "70db65ee-d533-4f6b-9ffa-a4d70a17b7ef"
BDE = "53a669d6-84b1-4352-8d7c-421c1fbd9c6a"
BDS = "0a728640-50d3-43a9-b26c-67a758698c44"
CAA = "6c6d7e88-fdb8-4e42-b2b5-3d3cfd12e7d6"
cinema = "ce5f36e6-5377-489f-9696-de70e2477300"
raid_admin = "e9e6e3d3-9f5f-4e9b-8e5f-9f5f4e9b8e5f"
Expand Down
252 changes: 252 additions & 0 deletions app/modules/sports_results/cruds_sport_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
from collections.abc import Sequence

Check failure on line 1 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (INP001)

app/modules/sports_results/cruds_sport_results.py:1:1: INP001 File `app/modules/sports_results/cruds_sport_results.py` is part of an implicit namespace package. Add an `__init__.py`.

Check failure on line 1 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (INP001)

app/modules/sports_results/cruds_sport_results.py:1:1: INP001 File `app/modules/sports_results/cruds_sport_results.py` is part of an implicit namespace package. Add an `__init__.py`.

Check failure on line 1 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (INP001)

app/modules/sports_results/cruds_sport_results.py:1:1: INP001 File `app/modules/sports_results/cruds_sport_results.py` is part of an implicit namespace package. Add an `__init__.py`.

Check failure on line 1 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (INP001)

app/modules/sports_results/cruds_sport_results.py:1:1: INP001 File `app/modules/sports_results/cruds_sport_results.py` is part of an implicit namespace package. Add an `__init__.py`.

from sqlalchemy import delete, select, update
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession

from app.modules.sports_results import models_sport_results, schemas_sport_results


async def get_sports(
db: AsyncSession,
) -> Sequence[models_sport_results.Sport]:
result = await db.execute(select(models_sport_results.Sport))
return result.scalars().all()


async def get_sport_by_id(
sport_id,
db: AsyncSession,
) -> models_sport_results.Sport | None:
result = await db.execute(
select(models_sport_results.Sport).where(
models_sport_results.Sport.id == sport_id,
),
)
return result.scalars().first()


async def get_captains_by_sport_id(
sport_id: str,
db: AsyncSession,
) -> Sequence[models_sport_results.Captain]:
result = await db.execute(
select(models_sport_results.Captain).where(
models_sport_results.Captain.sports.id == sport_id,
),
)
return result.scalars().all()


async def is_user_a_captain_of_a_sport(
user_id: str,
sport_id: str,
db: AsyncSession,
) -> bool:
result = await db.execute(
select(
models_sport_results.Captain,
).where(
models_sport_results.Captain.sports.any(
models_sport_results.Captain.sports.id == sport_id,
),
models_sport_results.Captain.user_id == user_id,
),
)

return result.unique().scalars().first() is not None


async def is_user_a_captain(
user_id: str,
db: AsyncSession,
) -> bool:
result = await db.execute(
select(
models_sport_results.Captain,
).where(
models_sport_results.Captain.user_id == user_id,
),
)

return result.unique().scalars().first() is not None


async def get_captain_by_id(
captain_id,
db: AsyncSession,
) -> models_sport_results.Captain | None:
captain = await db.execute(
select(models_sport_results.Captain).where(
models_sport_results.Captain.id == captain_id,
),
)
return captain.scalars().first()


async def get_result_by_id(
result_id,
db: AsyncSession,
) -> models_sport_results.Result | None:
result = await db.execute(
select(models_sport_results.Result).where(
models_sport_results.Result.id == result_id,
),
)
return result.scalars().first()


async def get_results(db: AsyncSession) -> Sequence[models_sport_results.Result]:
result = await db.execute(
select(models_sport_results.Result).order_by(
models_sport_results.Result.match_date,
),
)
return result.scalars().all()


async def get_results_by_sport_id(
sport_id,
db: AsyncSession,
) -> Sequence[models_sport_results.Result]:
result = await db.execute(
select(models_sport_results.Result)
.where(
models_sport_results.Result.sport_id == sport_id,
)
.order_by(
models_sport_results.Result.match_date,
),
)
return result.scalars().all()


async def add_result(
result: models_sport_results.Result,
db: AsyncSession,
) -> models_sport_results.Result:
db.add(result)
try:
await db.commit()
return result

Check failure on line 131 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:131:9: TRY300 Consider moving this statement to an `else` block

Check failure on line 131 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:131:9: TRY300 Consider moving this statement to an `else` block

Check failure on line 131 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:131:9: TRY300 Consider moving this statement to an `else` block

Check failure on line 131 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:131:9: TRY300 Consider moving this statement to an `else` block
except IntegrityError as error:
await db.rollback()
raise ValueError(error)


async def update_result(
result_id: str,
result_update: schemas_sport_results.ResultUpdate,
db: AsyncSession,
):
await db.execute(
update(models_sport_results.Result)
.where(
models_sport_results.Result.id == result_id,
)
.values(**result_update.model_dump(exclude_none=True)),
)
await db.commit()


async def delete_result(
result_id: str,
db: AsyncSession,
):
await db.execute(
delete(models_sport_results.Result).where(
models_sport_results.Result.id == result_id,
),
)
await db.commit()


async def add_captain(
captain: models_sport_results.Captain,
db: AsyncSession,
) -> models_sport_results.Captain:
db.add(captain)
try:
await db.commit()
return captain

Check failure on line 171 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:171:9: TRY300 Consider moving this statement to an `else` block

Check failure on line 171 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:171:9: TRY300 Consider moving this statement to an `else` block

Check failure on line 171 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:171:9: TRY300 Consider moving this statement to an `else` block

Check failure on line 171 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:171:9: TRY300 Consider moving this statement to an `else` block
except IntegrityError as error:
await db.rollback()
raise ValueError(error)


async def update_captain(
captain_id: str,
captain_update: schemas_sport_results.CaptainUpdate,
db: AsyncSession,
):
await db.execute(
update(models_sport_results.Captain)
.where(
models_sport_results.Captain.id == captain_id,
)
.values(**captain_update.model_dump(exclude_none=True)),
)
await db.commit()


async def delete_captain(
captain_id: str,
db: AsyncSession,
):
await db.execute(
delete(models_sport_results.Captain).where(
models_sport_results.Captain.id == captain_id,
),
)
await db.commit()


async def add_sport(
sport: models_sport_results.Sport,
db: AsyncSession,
) -> models_sport_results.Sport:
db.add(sport)
try:
await db.commit()
return sport

Check failure on line 211 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:211:9: TRY300 Consider moving this statement to an `else` block

Check failure on line 211 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:211:9: TRY300 Consider moving this statement to an `else` block

Check failure on line 211 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:211:9: TRY300 Consider moving this statement to an `else` block

Check failure on line 211 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (TRY300)

app/modules/sports_results/cruds_sport_results.py:211:9: TRY300 Consider moving this statement to an `else` block
except IntegrityError as error:
await db.rollback()
raise ValueError(error)


async def update_sport(
sport_id: str,
sport_update: schemas_sport_results.SportUpdate,
db: AsyncSession,
):
await db.execute(
update(models_sport_results.Sport)
.where(
models_sport_results.Sport.id == sport_id,
)
.values(**sport_update.model_dump(exclude_none=True)),
)
await db.commit()


async def delete_sport(
sport_id: str,
db: AsyncSession,
):
await db.execute(
delete(models_sport_results.Result).where(
models_sport_results.Result.sport_id == sport_id,
),
)
await db.execute(
#####################################
delete(models_sport_results.Captain).where(
models_sport_results.Captain.sports.id == sport_id,
),
)
await db.execute(
delete(models_sport_results.Sport).where(
models_sport_results.Sport.id == sport_id,
),
)
await db.commit()

Check failure on line 252 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (W292)

app/modules/sports_results/cruds_sport_results.py:252:22: W292 No newline at end of file

Check failure on line 252 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (W292)

app/modules/sports_results/cruds_sport_results.py:252:22: W292 No newline at end of file

Check failure on line 252 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (W292)

app/modules/sports_results/cruds_sport_results.py:252:22: W292 No newline at end of file

Check failure on line 252 in app/modules/sports_results/cruds_sport_results.py

View workflow job for this annotation

GitHub Actions / test

Ruff (W292)

app/modules/sports_results/cruds_sport_results.py:252:22: W292 No newline at end of file
Loading
Loading