diff options
Diffstat (limited to 'routers/tmdb.py')
| -rw-r--r-- | routers/tmdb.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/routers/tmdb.py b/routers/tmdb.py index 5f7943f..f56a9df 100644 --- a/routers/tmdb.py +++ b/routers/tmdb.py @@ -3,7 +3,7 @@ from dotenv import load_dotenv from fastapi import APIRouter, Query from fastapi.responses import JSONResponse -from services.tmdb import TMDBNotConfiguredError, search_movies, movie_images +from services.tmdb import TMDBNotConfiguredError, search_movies, movie_images, movie_detail, movie_payload load_dotenv() @@ -32,6 +32,24 @@ async def search_tmdb(q: str = Query(..., min_length=2)): ) +@router.get("/detail/{tmdb_id}") +async def tmdb_detail(tmdb_id: int): + try: + async with httpx.AsyncClient(timeout=10.0) as client: + detail = await movie_detail(client, tmdb_id) + return movie_payload(detail) + except TMDBNotConfiguredError: + return JSONResponse( + status_code=503, + content={"error": "TMDB_API_KEY is not configured."}, + ) + except httpx.HTTPError: + return JSONResponse( + status_code=502, + content={"error": "Failed to fetch TMDB details."}, + ) + + @router.get("/posters") async def tmdb_posters(tmdb_id: int = Query(...)): try: |
