45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Series 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.tv import SeriesDetailOut, SeriesSeasonsOut
|
||
|
|
from app.services import tv_service
|
||
|
|
from app.services.cache import build_key
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/series", tags=["series"], dependencies=[Depends(enforce_rate_limit)])
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/{aurora_id}", response_model=SeriesDetailOut)
|
||
|
|
async def get_series(
|
||
|
|
aurora_id: str,
|
||
|
|
session: AsyncSession = Depends(get_db),
|
||
|
|
redis: Redis = Depends(get_redis),
|
||
|
|
) -> SeriesDetailOut:
|
||
|
|
try:
|
||
|
|
return await cached_response(
|
||
|
|
redis,
|
||
|
|
build_key("series", aurora_id),
|
||
|
|
SeriesDetailOut,
|
||
|
|
lambda: tv_service.get_series_detail(session, aurora_id),
|
||
|
|
)
|
||
|
|
except tv_service.SeriesNotFoundError as exc:
|
||
|
|
raise not_found("series", aurora_id) from exc
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/{aurora_id}/seasons", response_model=SeriesSeasonsOut)
|
||
|
|
async def get_series_seasons(
|
||
|
|
aurora_id: str, session: AsyncSession = Depends(get_db)
|
||
|
|
) -> SeriesSeasonsOut:
|
||
|
|
try:
|
||
|
|
return await tv_service.get_series_seasons(session, aurora_id)
|
||
|
|
except tv_service.SeriesNotFoundError as exc:
|
||
|
|
raise not_found("series", aurora_id) from exc
|