| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- # app/services/slot_snapshot_service.py
- from sqlalchemy.ext.asyncio import AsyncSession
- from sqlalchemy import select
- from app.models.slot_snapshot import VasSlotSnapshot
- from app.schemas.slot_snapshot import SlotSnapshotCreate
- class SlotSnapshotService:
- @staticmethod
- async def create(
- db: AsyncSession,
- data: SlotSnapshotCreate
- ) -> VasSlotSnapshot:
- rec = VasSlotSnapshot(**data.dict())
- db.add(rec)
- await db.commit()
- await db.refresh(rec)
- return rec
- @staticmethod
- async def latest_for(
- db: AsyncSession,
- country: str,
- city: str,
- visa_type: str
- ) -> VasSlotSnapshot:
- stmt = (
- select(VasSlotSnapshot)
- .where(
- VasSlotSnapshot.country == country,
- VasSlotSnapshot.city == city,
- VasSlotSnapshot.visa_type == visa_type,
- )
- .order_by(VasSlotSnapshot.snapshot_at.desc())
- .limit(1)
- )
- return await db.scalar(stmt)
|