diff options
Diffstat (limited to 'routers/tmdb.py')
| -rw-r--r-- | routers/tmdb.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/routers/tmdb.py b/routers/tmdb.py new file mode 100644 index 0000000..522c1d0 --- /dev/null +++ b/routers/tmdb.py @@ -0,0 +1,32 @@ +import httpx +from dotenv import load_dotenv +from fastapi import APIRouter, Query +from fastapi.responses import JSONResponse + +from services.tmdb import TMDBNotConfiguredError, search_movies + +load_dotenv() + +router = APIRouter(prefix="/tmdb", tags=["tmdb"]) + + +@router.get("/search") +async def search_tmdb(q: str = Query(..., min_length=2)): + try: + return {"results": await search_movies(q, limit=8, include_details=True)} + except TMDBNotConfiguredError: + return JSONResponse( + status_code=503, + content={ + "error": "TMDB_API_KEY is not configured.", + "results": [], + }, + ) + except httpx.HTTPError: + return JSONResponse( + status_code=502, + content={ + "error": "TMDB search failed. Check your API key and try again.", + "results": [], + }, + ) |
