Endpoint /api/v1/louka/fairvalue/{uid} : juste valeur Lou-Ka en direct (proxy)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 changed file +24 −0
modified
src/api/routes/services.py
+24 −0
@@ -192,3 +192,27 @@ def list_service_data( | ||
| 192 | 192 | total=total, |
| 193 | 193 | extra_meta={"service": service}, |
| 194 | 194 | ) |
| 195 | + | |
| 196 | + | |
| 197 | +@router.get("/louka/fairvalue/{uid}") | |
| 198 | +def louka_fairvalue(uid: str = Path(..., description="uid d'annonce lou-ka")): | |
| 199 | + """Juste valeur locative Lou-Ka (fair value) EN DIRECT : valeur estimée, | |
| 200 | + fourchette, indice de confiance, classification sous/dans/au-dessus du | |
| 201 | + marché et distribution du segment — proxifié depuis l'API lou-ka | |
| 202 | + (framework louka/fairvalue.py). Utilisé par l'app iOS KA.""" | |
| 203 | + import os | |
| 204 | + | |
| 205 | + import httpx | |
| 206 | + | |
| 207 | + base = (os.environ.get("LOUKA_SOURCE_URL") | |
| 208 | + or "http://127.0.0.1:8095/api/listings").rsplit("/api/", 1)[0] | |
| 209 | + try: | |
| 210 | + resp = httpx.get(f"{base}/api/fairvalue/{uid}", timeout=10) | |
| 211 | + except httpx.HTTPError as exc: | |
| 212 | + raise HTTPException(status_code=502, detail=f"lou-ka injoignable: {exc}") | |
| 213 | + if resp.status_code == 404: | |
| 214 | + raise HTTPException(status_code=404, | |
| 215 | + detail="Pas d'estimation pour cette annonce") | |
| 216 | + resp.raise_for_status() | |
| 217 | + return envelope([resp.json()], | |
| 218 | + extra_meta={"service": "louka", "kind": "fairvalue"}) | |
| 195 | 219 | |