45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Person 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.person import PersonCreditsOut, PersonDetailOut
|
||
|
|
from app.services import person_service
|
||
|
|
from app.services.cache import build_key
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/people", tags=["people"], dependencies=[Depends(enforce_rate_limit)])
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/{aurora_id}", response_model=PersonDetailOut)
|
||
|
|
async def get_person(
|
||
|
|
aurora_id: str,
|
||
|
|
session: AsyncSession = Depends(get_db),
|
||
|
|
redis: Redis = Depends(get_redis),
|
||
|
|
) -> PersonDetailOut:
|
||
|
|
try:
|
||
|
|
return await cached_response(
|
||
|
|
redis,
|
||
|
|
build_key("person", aurora_id),
|
||
|
|
PersonDetailOut,
|
||
|
|
lambda: person_service.get_person_detail(session, aurora_id),
|
||
|
|
)
|
||
|
|
except person_service.PersonNotFoundError as exc:
|
||
|
|
raise not_found("person", aurora_id) from exc
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/{aurora_id}/credits", response_model=PersonCreditsOut)
|
||
|
|
async def get_person_credits(
|
||
|
|
aurora_id: str, session: AsyncSession = Depends(get_db)
|
||
|
|
) -> PersonCreditsOut:
|
||
|
|
try:
|
||
|
|
return await person_service.get_person_credits(session, aurora_id)
|
||
|
|
except person_service.PersonNotFoundError as exc:
|
||
|
|
raise not_found("person", aurora_id) from exc
|