Add GET /companies 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
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
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]>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
6aa9f0b840
commit
92b0f4e077
@@ -4,10 +4,11 @@ from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.company import Company, MovieCompany, SeriesCompany
|
||||
from app.models.enums import CompanyType
|
||||
from app.models.movie import Movie
|
||||
from app.models.tv import Series
|
||||
|
||||
@@ -37,3 +38,30 @@ async def get_company_series(session: AsyncSession, company_id: uuid.UUID) -> li
|
||||
)
|
||||
result = await session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def list_companies(
|
||||
session: AsyncSession,
|
||||
*,
|
||||
company_type: CompanyType | None,
|
||||
country_code: str | None,
|
||||
limit: int,
|
||||
offset: int,
|
||||
) -> tuple[list[Company], int]:
|
||||
"""Browse companies -- see movie_repository.list_movies for the
|
||||
window-function total-count approach this mirrors. Companies have no
|
||||
popularity/date equivalent to sort by, so this always orders
|
||||
alphabetically by name (with an id tiebreak for stable pagination)."""
|
||||
|
||||
stmt = select(Company, func.count().over().label("total_count"))
|
||||
if company_type is not None:
|
||||
stmt = stmt.where(Company.company_type == company_type)
|
||||
if country_code is not None:
|
||||
stmt = stmt.where(Company.country_code == country_code)
|
||||
|
||||
stmt = stmt.order_by(Company.name.asc(), Company.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
|
||||
|
||||
Reference in New Issue
Block a user