Files
Aurora-Core/app/api/v1/movies.py
T
NixReaperandClaude Sonnet 5 567b4ef068
CI / lint (push) Canceled after 0s
CI / typecheck (push) Canceled after 0s
CI / unit-tests (push) Canceled after 0s
CI / integration-tests (push) Canceled after 0s
CI / container-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s
Add keyword browsing/filtering and expose alternate titles
Keywords were ingested and shown read-only on detail pages, but had no
directory (GET /keywords) or filter param -- the same gap genres had
before today. Mirrors the genre browse pattern exactly: repository,
service, route, plus a `keyword` filter on GET /movies and GET /series.

Alternate/translated titles ("Also Known As") were normalized down to
bare title strings and never written to MovieAlternateTitle/
SeriesAlternateTitle at all. Normalizer now captures country_code + type
per TMDb's actual shape; ingestion writes them; movie/series detail now
expose an alternate_titles list.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-06 04:40:32 -05:00

112 lines
3.9 KiB
Python

"""Movie endpoints (section 17)."""
from __future__ import annotations
from typing import Literal
from fastapi import APIRouter, Depends, HTTPException, Query, status
from redis.asyncio import Redis
from sqlalchemy.ext.asyncio import AsyncSession
from app.api.deps import cached_response, not_found
from app.core.database import get_db
from app.core.redis import get_redis
from app.core.security import enforce_rate_limit
from app.schemas.movie import (
MovieCreditsOut,
MovieDetailOut,
MovieImagesOut,
MovieListOut,
MovieRecommendationsOut,
MovieVideosOut,
)
from app.services import movie_service
from app.services.cache import build_key
router = APIRouter(prefix="/movies", tags=["movies"], dependencies=[Depends(enforce_rate_limit)])
@router.get("", response_model=MovieListOut)
async def list_movies(
genre: str | None = Query(None, description="Aurora genre id, e.g. aur_genre_..."),
keyword: str | None = Query(None, description="Aurora keyword id, e.g. aur_keyword_..."),
year: int | None = Query(None, description="Primary release year"),
status_: str | None = Query(None, alias="status", description="Movie status, e.g. released"),
sort_by: Literal["popularity", "release_date", "vote_average", "title"] = Query("popularity"),
sort_dir: Literal["asc", "desc"] = Query("desc"),
page: int = Query(1, ge=1),
page_size: int = Query(20, ge=1, le=50),
session: AsyncSession = Depends(get_db),
) -> MovieListOut:
try:
return await movie_service.list_movies(
session,
genre_aurora_id=genre,
keyword_aurora_id=keyword,
year=year,
status=status_,
sort_by=sort_by,
sort_dir=sort_dir,
page=page,
page_size=page_size,
)
except movie_service.InvalidMovieFilterError as exc:
raise HTTPException(status.HTTP_422_UNPROCESSABLE_CONTENT, str(exc)) from exc
@router.get("/{aurora_id}", response_model=MovieDetailOut)
async def get_movie(
aurora_id: str,
session: AsyncSession = Depends(get_db),
redis: Redis = Depends(get_redis),
) -> MovieDetailOut:
try:
return await cached_response(
redis,
build_key("movie", aurora_id),
MovieDetailOut,
lambda: movie_service.get_movie_detail(session, aurora_id),
)
except movie_service.MovieNotFoundError as exc:
raise not_found("movie", aurora_id) from exc
@router.get("/{aurora_id}/credits", response_model=MovieCreditsOut)
async def get_movie_credits(
aurora_id: str, session: AsyncSession = Depends(get_db)
) -> MovieCreditsOut:
try:
return await movie_service.get_movie_credits(session, aurora_id)
except movie_service.MovieNotFoundError as exc:
raise not_found("movie", aurora_id) from exc
@router.get("/{aurora_id}/images", response_model=MovieImagesOut)
async def get_movie_images(
aurora_id: str, session: AsyncSession = Depends(get_db)
) -> MovieImagesOut:
try:
return await movie_service.get_movie_images(session, aurora_id)
except movie_service.MovieNotFoundError as exc:
raise not_found("movie", aurora_id) from exc
@router.get("/{aurora_id}/videos", response_model=MovieVideosOut)
async def get_movie_videos(
aurora_id: str, session: AsyncSession = Depends(get_db)
) -> MovieVideosOut:
try:
return await movie_service.get_movie_videos(session, aurora_id)
except movie_service.MovieNotFoundError as exc:
raise not_found("movie", aurora_id) from exc
@router.get("/{aurora_id}/recommendations", response_model=MovieRecommendationsOut)
async def get_movie_recommendations(
aurora_id: str, session: AsyncSession = Depends(get_db)
) -> MovieRecommendationsOut:
try:
return await movie_service.get_movie_recommendations(session, aurora_id)
except movie_service.MovieNotFoundError as exc:
raise not_found("movie", aurora_id) from exc