"""Warstwa LOGICZNA — usługa HTTP. W górę: udostępnia API dla warstwy prezentacji. W dół: woła warstwę bazodanową (DataClient). Nie serwuje HTML, nie czyta plików/baz — tylko reguły i pośrednictwo. """ from __future__ import annotations import httpx from fastapi import FastAPI, HTTPException from app.clients.data_client import DataClient from app.models import QueryRequest, QueryResponse from app.service import QueryService app = FastAPI(title="astrololo · warstwa logiczna") service = QueryService() @app.post("/api/query", response_model=QueryResponse) def query(req: QueryRequest) -> QueryResponse: try: return service.handle(req) except httpx.HTTPError as e: raise HTTPException(status_code=502, detail=f"Warstwa bazodanowa niedostępna: {e}") @app.get("/health") def health() -> dict: info = {"status": "ok", "layer": "logic"} try: info["data_layer"] = DataClient().health() except httpx.HTTPError as e: info["data_layer"] = {"status": "down", "error": str(e)} return info