"""Klient HTTP do warstwy bazodanowej. Jedyny punkt styku w dół. Gdyby warstwa bazodanowa zmieniła implementację (Excel→SQL), tutaj nie zmienia się NIC — kontrakt /search jest stały. """ from __future__ import annotations from typing import Any import httpx from app.config import settings class DataClient: def __init__(self, base_url: str | None = None) -> None: self.base_url = (base_url or settings.data_url).rstrip("/") def search( self, key: str, value: str, exact: bool, limit: int, fields: list[str] | None = None, ) -> dict[str, Any]: payload = {"key": key, "value": value, "exact": exact, "limit": limit, "fields": fields} with httpx.Client(timeout=max(settings.http_timeout, 30.0)) as client: r = client.post(f"{self.base_url}/search", json=payload) r.raise_for_status() return r.json() def health(self) -> dict[str, Any]: with httpx.Client(timeout=settings.http_timeout) as client: r = client.get(f"{self.base_url}/health") r.raise_for_status() return r.json()