summaryrefslogtreecommitdiff
path: root/routers/tmdb.py
diff options
context:
space:
mode:
authorTyler Hoang <tyler@tylerhoang.xyz>2026-05-06 12:21:26 -0700
committerTyler Hoang <tyler@tylerhoang.xyz>2026-05-06 12:21:26 -0700
commite708bec6cd76c2686de4158dde4d04f72a3c300d (patch)
tree04b0bc4738e090dd7834d47478c7e652da010f92 /routers/tmdb.py
init: lumiere film diary
Diffstat (limited to 'routers/tmdb.py')
-rw-r--r--routers/tmdb.py32
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": [],
+ },
+ )