mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Move the EpcClientService package (client + _retry + exceptions + tests) from the dying backend/ tree to infrastructure/epc_client/ as the New-EPC-API Fetcher; update the two callers (address2UPRN, a script). All 14 client tests pass. Add SolarRepository port + SolarPostgresRepository persisting Google Solar building insights as JSONB (solar_building_insights table), one row per Property. The EPC repo half of this slice already landed in #1129. pyright strict clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any, Optional
|
|
|
|
from sqlmodel import Session, select
|
|
|
|
from infrastructure.postgres.solar_table import SolarBuildingInsightsRow
|
|
from repositories.solar.solar_repository import SolarRepository
|
|
|
|
|
|
class SolarPostgresRepository(SolarRepository):
|
|
def __init__(self, session: Session) -> None:
|
|
self._session = session
|
|
|
|
def save(self, property_id: int, insights: dict[str, Any]) -> None:
|
|
existing = self._session.exec(
|
|
select(SolarBuildingInsightsRow).where(
|
|
SolarBuildingInsightsRow.property_id == property_id
|
|
)
|
|
).first()
|
|
if existing is None:
|
|
self._session.add(
|
|
SolarBuildingInsightsRow(property_id=property_id, insights=insights)
|
|
)
|
|
else:
|
|
existing.insights = insights
|
|
self._session.add(existing)
|
|
|
|
def get(self, property_id: int) -> Optional[dict[str, Any]]:
|
|
row = self._session.exec(
|
|
select(SolarBuildingInsightsRow).where(
|
|
SolarBuildingInsightsRow.property_id == property_id
|
|
)
|
|
).first()
|
|
return row.insights if row is not None else None
|