Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
58 lines
2.6 KiB
Python
58 lines
2.6 KiB
Python
"""OTT catalog data access (MV1): owner-scoped reads and writes, no business rules."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from .models import STATUS_PUBLISHED, OttChannel, OttCollection, OttSeries, OttTitle
|
|
|
|
|
|
class OttRepository:
|
|
def __init__(self, session: Session) -> None:
|
|
self.s = session
|
|
|
|
def channel_for_user(self, user_id: str) -> OttChannel | None:
|
|
return self.s.execute(select(OttChannel).where(OttChannel.user_id == user_id)).scalar_one_or_none()
|
|
|
|
def channel_by_handle(self, handle: str) -> OttChannel | None:
|
|
return self.s.execute(select(OttChannel).where(OttChannel.handle == handle)).scalar_one_or_none()
|
|
|
|
def channel_by_domain(self, domain: str) -> OttChannel | None:
|
|
return self.s.execute(select(OttChannel).where(OttChannel.custom_domain == domain)).scalar_one_or_none()
|
|
|
|
def handle_taken(self, handle: str) -> bool:
|
|
return self.channel_by_handle(handle) is not None
|
|
|
|
def titles(self, channel_id: str, *, published_only: bool = False) -> list[OttTitle]:
|
|
query = select(OttTitle).where(OttTitle.channel_id == channel_id)
|
|
if published_only:
|
|
query = query.where(OttTitle.status == STATUS_PUBLISHED)
|
|
return list(self.s.execute(query.order_by(OttTitle.position, OttTitle.created_at)).scalars().all())
|
|
|
|
def title(self, channel_id: str, title_id: str) -> OttTitle | None:
|
|
row = self.s.get(OttTitle, title_id)
|
|
return row if row is not None and row.channel_id == channel_id else None
|
|
|
|
def title_for_job(self, channel_id: str, job_id: str) -> OttTitle | None:
|
|
return self.s.execute(select(OttTitle).where(OttTitle.channel_id == channel_id,
|
|
OttTitle.source_job_id == job_id)).scalar_one_or_none()
|
|
|
|
def titles_for_job(self, job_id: str) -> list[OttTitle]:
|
|
return list(self.s.execute(select(OttTitle).where(OttTitle.source_job_id == job_id)).scalars().all())
|
|
|
|
def series(self, channel_id: str) -> list[OttSeries]:
|
|
return list(self.s.execute(select(OttSeries).where(OttSeries.channel_id == channel_id)
|
|
.order_by(OttSeries.position)).scalars().all())
|
|
|
|
def collections(self, channel_id: str) -> list[OttCollection]:
|
|
return list(self.s.execute(select(OttCollection).where(OttCollection.channel_id == channel_id)
|
|
.order_by(OttCollection.position)).scalars().all())
|
|
|
|
def add(self, row: Any) -> Any:
|
|
self.s.add(row)
|
|
self.s.flush()
|
|
return row
|