refactor main.py
Some checks failed
CI and deploy / migration-check (push) Failing after 17s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-04-19 20:42:53 +02:00
parent ccb2a41e22
commit 014c6f193b
7 changed files with 1229 additions and 1062 deletions

33
backend/app/routers/me.py Normal file
View File

@@ -0,0 +1,33 @@
"""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]