visus-plus/api/app/application/appointment_files_repository.py
andrei eb4890e97b feat: Добавлена работа с файлами приемов
Добавлены API для загрузки, скачивания и удаления файлов приемов.
Обновлен UI страницы приемов.
2025-06-03 22:45:01 +05:00

33 lines
1.1 KiB
Python

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