Clear project — starting fresh from spec
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.registration import Registration
|
||||
|
||||
|
||||
def _uuid(v: str | uuid.UUID) -> uuid.UUID:
|
||||
return v if isinstance(v, uuid.UUID) else uuid.UUID(str(v))
|
||||
|
||||
|
||||
async def get(db: AsyncSession, registration_id: str | uuid.UUID) -> Registration | None:
|
||||
result = await db.execute(
|
||||
select(Registration).where(Registration.id == _uuid(registration_id))
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_by_champ_and_user(
|
||||
db: AsyncSession, championship_id: str | uuid.UUID, user_id: str | uuid.UUID
|
||||
) -> Registration | None:
|
||||
result = await db.execute(
|
||||
select(Registration).where(
|
||||
Registration.championship_id == _uuid(championship_id),
|
||||
Registration.user_id == _uuid(user_id),
|
||||
)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def list_by_user(db: AsyncSession, user_id: str | uuid.UUID) -> list[Registration]:
|
||||
result = await db.execute(
|
||||
select(Registration)
|
||||
.where(Registration.user_id == _uuid(user_id))
|
||||
.order_by(Registration.submitted_at.desc())
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def list_by_championship(
|
||||
db: AsyncSession, championship_id: str | uuid.UUID
|
||||
) -> list[Registration]:
|
||||
result = await db.execute(
|
||||
select(Registration)
|
||||
.where(Registration.championship_id == _uuid(championship_id))
|
||||
.order_by(Registration.submitted_at.asc())
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def create(
|
||||
db: AsyncSession,
|
||||
championship_id: uuid.UUID,
|
||||
user_id: uuid.UUID,
|
||||
category: str | None,
|
||||
level: str | None,
|
||||
notes: str | None,
|
||||
) -> Registration:
|
||||
reg = Registration(
|
||||
championship_id=championship_id,
|
||||
user_id=user_id,
|
||||
category=category,
|
||||
level=level,
|
||||
notes=notes,
|
||||
)
|
||||
db.add(reg)
|
||||
await db.commit()
|
||||
await db.refresh(reg)
|
||||
return reg
|
||||
|
||||
|
||||
async def update_status(
|
||||
db: AsyncSession, reg: Registration, status: str
|
||||
) -> Registration:
|
||||
reg.status = status
|
||||
reg.decided_at = datetime.now(timezone.utc)
|
||||
await db.commit()
|
||||
await db.refresh(reg)
|
||||
return reg
|
||||
|
||||
|
||||
async def delete(db: AsyncSession, reg: Registration) -> None:
|
||||
await db.delete(reg)
|
||||
await db.commit()
|
||||
Reference in New Issue
Block a user