summaryrefslogtreecommitdiff
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/films.py17
-rw-r--r--routers/tmdb.py15
2 files changed, 31 insertions, 1 deletions
diff --git a/routers/films.py b/routers/films.py
index ec56c0a..4ac023c 100644
--- a/routers/films.py
+++ b/routers/films.py
@@ -467,6 +467,23 @@ async def update_film_stars(film_id: int, request: Request, db: Session = Depend
return {"film_id": film.id, "stars": film.stars}
+@router.post("/films/{film_id}/poster")
+async def update_film_poster(film_id: int, request: Request, db: Session = Depends(get_db)):
+ film = _get_film_or_404(db, film_id)
+ try:
+ payload = await request.json()
+ except Exception as exc: # noqa: BLE001
+ raise HTTPException(status_code=400, detail="Request body must be JSON.") from exc
+
+ poster_url = payload.get("poster_url", "").strip()
+ if not poster_url:
+ raise HTTPException(status_code=400, detail="poster_url is required.")
+
+ film.poster_url = poster_url
+ db.commit()
+ return {"film_id": film.id, "poster_url": film.poster_url}
+
+
@router.get("/director/{director_name}")
async def director_detail(director_name: str, request: Request, db: Session = Depends(get_db)):
films = _director_films(db, director_name)
diff --git a/routers/tmdb.py b/routers/tmdb.py
index 522c1d0..5f7943f 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
+from services.tmdb import TMDBNotConfiguredError, search_movies, movie_images
load_dotenv()
@@ -30,3 +30,16 @@ async def search_tmdb(q: str = Query(..., min_length=2)):
"results": [],
},
)
+
+
+@router.get("/posters")
+async def tmdb_posters(tmdb_id: int = Query(...)):
+ try:
+ async with httpx.AsyncClient(timeout=10.0) as client:
+ urls = await movie_images(client, tmdb_id)
+ return {"posters": urls}
+ except TMDBNotConfiguredError:
+ return JSONResponse(
+ status_code=503,
+ content={"error": "TMDB_API_KEY is not configured.", "posters": []},
+ )