from typing import Optional, Sequence from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession from app.domain.models import ContestFile class ContestFilesRepository: def __init__(self, db: AsyncSession): self.db = db async def get_by_id(self, file_id: int) -> Optional[ContestFile]: stmt = select(ContestFile).filter_by(id=file_id) result = await self.db.execute(stmt) return result.scalars().first() async def get_by_contest_id(self, contest_id: int) -> Sequence[ContestFile]: stmt = select(ContestFile).filter_by(contest_id=contest_id) result = await self.db.execute(stmt) return result.scalars().all() async def create(self, contest_file: ContestFile) -> ContestFile: self.db.add(contest_file) await self.db.commit() await self.db.refresh(contest_file) return contest_file async def delete(self, contest_file: ContestFile) -> ContestFile: await self.db.delete(contest_file) await self.db.commit() return contest_file