From e708bec6cd76c2686de4158dde4d04f72a3c300d Mon Sep 17 00:00:00 2001 From: Tyler Hoang Date: Wed, 6 May 2026 12:21:26 -0700 Subject: init: lumiere film diary --- routers/tmdb.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 routers/tmdb.py (limited to 'routers/tmdb.py') 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": [], + }, + ) -- cgit v1.3-2-g0d8e