Files
Aurora-Core/app/api/v1/companies.py
T
NixReaperandClaude Sonnet 5 92b0f4e077
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 GET /companies browse/discover endpoint
Completes the browse/discover set across all four entity types.
Companies have no popularity or date field, so unlike movies/series/
people there's no sort_by choice -- always alphabetical by name.
Filters are company_type (validated against the enum) and country
(a plain ISO 3166-1 code comparison, nothing to validate).

build_company_summary refactored to share row-to-summary logic with
the new list path, same pattern used for movies/series/people.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-05 19:08:14 -05:00

45 lines
1.6 KiB
Python

"""Company endpoints (section 17)."""
from __future__ import annotations
from fastapi import APIRouter, Depends, HTTPException, Query, status
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
from app.schemas.company import CompanyDetailOut, CompanyListOut
from app.services import company_service
router = APIRouter(
prefix="/companies", tags=["companies"], dependencies=[Depends(enforce_rate_limit)]
)
@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
@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