Add GET /people browse/discover endpoint
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

Extends the browse/discover pattern already built for movies/series
to the fourth major entity type. No genre/year/status equivalent for
people -- known_for_department is the one categorical filter that
actually means something for a cast/crew list, and sort_by is just
popularity (default) or name. No invalid-filter case either: unlike
genre/status, known_for_department is a plain string compared
directly, nothing to parse or validate.

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

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
NixReaper
2026-09-05 10:32:16 -05:00
co-authored by Claude Sonnet 5
parent 74adcf77bc
commit 6aa9f0b840
6 changed files with 257 additions and 10 deletions
+36 -1
View File
@@ -4,12 +4,17 @@ from __future__ import annotations
import uuid
from sqlalchemy import select
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.credit import Credit
from app.models.person import Person
_PERSON_SORT_COLUMNS = {
"popularity": Person.popularity,
"name": Person.name,
}
async def get_person_by_id(session: AsyncSession, person_id: uuid.UUID) -> Person | None:
result = await session.execute(select(Person).where(Person.id == person_id))
@@ -24,3 +29,33 @@ async def get_person_credits(session: AsyncSession, person_id: uuid.UUID) -> lis
)
result = await session.execute(stmt)
return list(result.scalars().all())
async def list_people(
session: AsyncSession,
*,
known_for_department: str | None,
sort_by: str,
sort_dir: str,
limit: int,
offset: int,
) -> tuple[list[Person], int]:
"""Browse people with an optional known_for_department filter -- see
movie_repository.list_movies for the window-function total-count
approach this mirrors. No genre/year/status equivalent for people:
department is the one categorical grouping that actually means
something when browsing a cast/crew list."""
column = _PERSON_SORT_COLUMNS[sort_by]
order = column.desc() if sort_dir == "desc" else column.asc()
stmt = select(Person, func.count().over().label("total_count"))
if known_for_department is not None:
stmt = stmt.where(Person.known_for_department == known_for_department)
stmt = stmt.order_by(order.nulls_last(), Person.id.asc()).limit(limit).offset(offset)
rows = (await session.execute(stmt)).all()
if not rows:
return [], 0
return [row[0] for row in rows], rows[0].total_count