"""Movie endpoints (section 17).""" from __future__ import annotations from fastapi import APIRouter, Depends 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, 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("/{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