2026-09-04 17:34:03 -05:00
|
|
|
"""Company endpoints (section 17)."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-09-05 19:08:14 -05:00
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
2026-09-04 17:34:03 -05:00
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
|
|
|
|
from app.api.deps import not_found
|
|
|
|
|
from app.core.database import get_db
|
|
|
|
|
from app.core.security import enforce_rate_limit
|
2026-09-05 19:08:14 -05:00
|
|
|
from app.schemas.company import CompanyDetailOut, CompanyListOut
|
2026-09-04 17:34:03 -05:00
|
|
|
from app.services import company_service
|
|
|
|
|
|
|
|
|
|
router = APIRouter(
|
|
|
|
|
prefix="/companies", tags=["companies"], dependencies=[Depends(enforce_rate_limit)]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-09-05 19:08:14 -05:00
|
|
|
@router.get("", response_model=CompanyListOut)
|
|
|
|
|
async def list_companies(
|
|
|
|
|
company_type: str | None = Query(
|
|
|
|
|
None, description="production_company, network, studio, or distributor"
|
|
|
|
|
),
|
|
|
|
|
country: str | None = Query(None, description="ISO 3166-1 alpha-2 country code, e.g. US"),
|
|
|
|
|
page: int = Query(1, ge=1),
|
|
|
|
|
page_size: int = Query(20, ge=1, le=50),
|
|
|
|
|
session: AsyncSession = Depends(get_db),
|
|
|
|
|
) -> CompanyListOut:
|
|
|
|
|
try:
|
|
|
|
|
return await company_service.list_companies(
|
|
|
|
|
session, company_type=company_type, country=country, page=page, page_size=page_size
|
|
|
|
|
)
|
|
|
|
|
except company_service.InvalidCompanyFilterError as exc:
|
|
|
|
|
raise HTTPException(status.HTTP_422_UNPROCESSABLE_CONTENT, str(exc)) from exc
|
|
|
|
|
|
|
|
|
|
|
2026-09-04 17:34:03 -05:00
|
|
|
@router.get("/{aurora_id}", response_model=CompanyDetailOut)
|
|
|
|
|
async def get_company(
|
|
|
|
|
aurora_id: str, session: AsyncSession = Depends(get_db)
|
|
|
|
|
) -> CompanyDetailOut:
|
|
|
|
|
try:
|
|
|
|
|
return await company_service.get_company_detail(session, aurora_id)
|
|
|
|
|
except company_service.CompanyNotFoundError as exc:
|
|
|
|
|
raise not_found("company", aurora_id) from exc
|