Files

51 lines
1.7 KiB
Python
Raw Permalink Normal View History

"""Proxy recommendations to Tools API."""
from __future__ import annotations
import os
import httpx
from fastapi import APIRouter
admin_router = None # patched into admin_api
TOOLS = os.getenv("TOOLS_API_URL", "http://tools-api:8700").rstrip("/")
async def _proxy(method: str, path: str):
async with httpx.AsyncClient(timeout=60) as client:
r = await getattr(client, method.lower())(f"{TOOLS}{path}")
return r.json()
def register_recommendation_routes(router: APIRouter) -> None:
@router.get("/recommendations/pending")
async def reco_pending():
return await _proxy("GET", "/recommendations/pending")
@router.post("/recommendations/generate")
async def reco_generate():
return await _proxy("POST", "/recommendations/generate")
@router.post("/recommendations/{rec_id}/approve")
async def reco_approve(rec_id: int):
return await _proxy("POST", f"/recommendations/{rec_id}/approve")
@router.post("/recommendations/{rec_id}/dismiss")
async def reco_dismiss(rec_id: int):
return await _proxy("POST", f"/recommendations/{rec_id}/dismiss")
@router.get("/recommendations/halal/live")
async def halal_reco_live(limit: int = 5, refresh: bool = False):
q = f"/recommendations/halal/live?limit={limit}"
if refresh:
q += "&refresh=true"
return await _proxy("GET", q)
@router.post("/recommendations/halal/refresh")
async def halal_reco_refresh(limit: int = 5):
return await _proxy("POST", f"/recommendations/halal/refresh?limit={limit}")
@router.post("/research/run")
async def research_run():
return await _proxy("POST", "/research/run")