fix
Some checks failed
CI and deploy / migration-check (push) Failing after 18s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-04-27 18:48:04 +02:00
parent e96bb75b87
commit 30585c9779
4 changed files with 89 additions and 11 deletions

View File

@@ -75,6 +75,47 @@ async def get_site_prices(
return [r for r in rows if isinstance(r, dict)]
@router.get("/{site_id}/prices/slots")
async def get_site_prices_slots_range(
site_id: int,
db: Annotated[asyncpg.Pool, Depends(get_pg_pool)],
from_ts: datetime = Query(
...,
alias="from",
description="Začátek okna [from, to), typicky UTC zaokrouhlené na 15 min",
),
to_ts: datetime = Query(
...,
alias="to",
description="Konec polouzavřeného intervalu (max. 14 dní za from)",
),
) -> dict[str, list[dict[str, Any]]]:
if to_ts <= from_ts:
raise HTTPException(status_code=422, detail="'to' must be after 'from'")
if to_ts - from_ts > timedelta(days=14):
raise HTTPException(
status_code=422,
detail="Span between 'from' and 'to' must be at most 14 days",
)
async with db.acquire() as conn:
site_ok = await conn.fetchval(
"SELECT EXISTS(SELECT 1 FROM ems.site WHERE id = $1)", site_id
)
if not site_ok:
raise HTTPException(status_code=404, detail="Site not found")
raw = await fetch_json(
conn,
"select ems.fn_site_effective_prices_slots_range($1::int, $2::timestamptz, $3::timestamptz)",
site_id,
from_ts,
to_ts,
)
rows = raw if isinstance(raw, list) else []
if not isinstance(rows, list):
rows = []
return {"slots": [r for r in rows if isinstance(r, dict)]}
class PricesImportResponse(BaseModel):
slots_imported: int
date: str