Add movies/series filmography to company detail
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
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
GET /companies/{id} showed only the company's own info. Adds movies
and series lists (any role: production, distribution, network),
ordered by release/first-air date, read straight off the existing
movie_companies/series_companies junction rows -- no separate sync
needed since those only ever exist as a side effect of ingesting the
movie or series itself.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
606d2532c4
commit
6956bf7406
@@ -7,9 +7,33 @@ import uuid
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.company import Company
|
||||
from app.models.company import Company, MovieCompany, SeriesCompany
|
||||
from app.models.movie import Movie
|
||||
from app.models.tv import Series
|
||||
|
||||
|
||||
async def get_company_by_id(session: AsyncSession, company_id: uuid.UUID) -> Company | None:
|
||||
result = await session.execute(select(Company).where(Company.id == company_id))
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_company_movies(session: AsyncSession, company_id: uuid.UUID) -> list[Movie]:
|
||||
stmt = (
|
||||
select(Movie)
|
||||
.join(MovieCompany, MovieCompany.movie_id == Movie.id)
|
||||
.where(MovieCompany.company_id == company_id)
|
||||
.order_by(Movie.primary_release_date.asc().nulls_last())
|
||||
)
|
||||
result = await session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def get_company_series(session: AsyncSession, company_id: uuid.UUID) -> list[Series]:
|
||||
stmt = (
|
||||
select(Series)
|
||||
.join(SeriesCompany, SeriesCompany.series_id == Series.id)
|
||||
.where(SeriesCompany.company_id == company_id)
|
||||
.order_by(Series.first_air_date.asc().nulls_last())
|
||||
)
|
||||
result = await session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
@@ -6,6 +6,9 @@ from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.schemas.movie import MovieSummaryOut
|
||||
from app.schemas.tv import SeriesSummaryOut
|
||||
|
||||
|
||||
class CompanyDetailOut(BaseModel):
|
||||
id: str
|
||||
@@ -20,5 +23,8 @@ class CompanyDetailOut(BaseModel):
|
||||
parent_company_id: str | None = None
|
||||
external_ids: dict[str, str] = {}
|
||||
|
||||
movies: list[MovieSummaryOut] = []
|
||||
series: list[SeriesSummaryOut] = []
|
||||
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
@@ -12,6 +12,8 @@ from app.repositories import company_repository, polymorphic
|
||||
from app.schemas.common import CompanyBriefOut
|
||||
from app.schemas.company import CompanyDetailOut
|
||||
from app.services.common import primary_artwork_path
|
||||
from app.services.movie_service import build_movie_summaries
|
||||
from app.services.tv_service import build_series_summaries
|
||||
|
||||
|
||||
class CompanyNotFoundError(Exception):
|
||||
@@ -33,6 +35,8 @@ async def get_company_detail(session: AsyncSession, company_aurora_id: str) -> C
|
||||
|
||||
logos = await polymorphic.get_artwork(session, "company", company_id, ArtworkType.LOGO)
|
||||
external_ids = await polymorphic.get_external_ids(session, "company", company_id)
|
||||
movies = await company_repository.get_company_movies(session, company_id)
|
||||
series = await company_repository.get_company_series(session, company_id)
|
||||
|
||||
return CompanyDetailOut(
|
||||
id=aurora_id("company", str(company.id)),
|
||||
@@ -49,6 +53,8 @@ async def get_company_detail(session: AsyncSession, company_aurora_id: str) -> C
|
||||
else None
|
||||
),
|
||||
external_ids=external_ids,
|
||||
movies=await build_movie_summaries(session, [m.id for m in movies]),
|
||||
series=await build_series_summaries(session, [s.id for s in series]),
|
||||
created_at=company.created_at,
|
||||
updated_at=company.updated_at,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user