Files
ems/backend/app/routers/me.py
Dusan Vojacek 014c6f193b
Some checks failed
CI and deploy / migration-check (push) Failing after 17s
CI and deploy / deploy (push) Has been skipped
refactor main.py
2026-04-19 20:42:53 +02:00

34 lines
991 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""REST API /me (fáze bez auth)."""
from __future__ import annotations
from typing import Annotated, Any
import asyncpg
from fastapi import APIRouter, Depends
from app.db_json import record_to_dict
from app.deps import get_pg_pool
router = APIRouter(prefix="/api/v1/me", tags=["me"])
@router.get(
"/sites",
summary="Lokality přihlášeného uživatele (fáze bez auth)",
description="Aktuálně vrací všechny aktivní lokality z vw_site_directory; po zavedení autentizace se odfiltruje podle oprávnění.",
)
async def list_my_sites(
db: Annotated[asyncpg.Pool, Depends(get_pg_pool)],
) -> list[dict[str, Any]]:
async with db.acquire() as conn:
rows = await conn.fetch(
"""
SELECT id, code, name, timezone, latitude, longitude, active, notes, created_at
FROM ems.vw_site_directory
WHERE active = true
ORDER BY code
"""
)
return [record_to_dict(r) for r in rows]