Model/repositories/condition/property_reference_reader_postgres.py
Khalim Conn-Kowlessar 19e278e6ed Read portfolio property references from Postgres for UPRN resolution
Postgres adapter for PropertyReferenceReader: selects landlord_property_id and
uprn from the property table for a portfolio, feeding PropertyUprnLookup. Thin
I/O over the FE-owned property table; exercised end-to-end where a DB is
available (no DB in this environment).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-13 15:06:44 +00:00

28 lines
997 B
Python

from typing import List
from sqlmodel import Session, select
from infrastructure.postgres.property_table import PropertyRow
from repositories.condition.property_reference_reader import (
PropertyReference,
PropertyReferenceReader,
)
class PropertyReferenceReaderPostgres(PropertyReferenceReader):
"""Reads landlord-reference -> UPRN pairs from the ``property`` table for a
portfolio. The reference key is ``landlord_property_id`` (ADR-0064)."""
def __init__(self, session: Session) -> None:
self._session = session
def references_for_portfolio(self, portfolio_id: int) -> List[PropertyReference]:
rows = self._session.exec(
select(PropertyRow.landlord_property_id, PropertyRow.uprn).where(
PropertyRow.portfolio_id == portfolio_id
)
).all()
return [
PropertyReference(landlord_property_id=landlord_property_id, uprn=uprn)
for landlord_property_id, uprn in rows
]