mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-27 23:35:01 +00:00
Behaviour-preserving lift-and-shift of the condition module out of legacy backend/condition/ into domain/condition, infrastructure/condition, infrastructure/postgres/condition_tables.py, repositories/condition, applications/condition, and tests/condition. Imports rewritten to the DDD paths; ConditionPostgres and the ORM models keep the legacy backend.app.db Base/db_session bridges so the existing suite proves behaviour is unchanged (SQLModel + session-DI conversion tracked as a follow-up in ADR-0064). 16 condition tests pass at the new location. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
from typing import Any, BinaryIO, List, Optional
|
|
from datetime import datetime
|
|
|
|
from applications.condition.condition_trigger_request import ConditionFileType
|
|
from repositories.condition.uprn_lookup import UprnLookup
|
|
from utils.logger import setup_logger
|
|
from domain.condition.mapping.mapper import Mapper
|
|
from domain.condition.property_condition_survey import PropertyConditionSurvey
|
|
from infrastructure.condition.parsing.parser import Parser
|
|
from repositories.condition.condition_postgres import ConditionPostgres
|
|
from applications.condition.factory import select_parser, select_mapper
|
|
|
|
logger = setup_logger()
|
|
|
|
|
|
def process_file(
|
|
file_stream: BinaryIO,
|
|
file_type: ConditionFileType,
|
|
uprn_lookup: Optional[UprnLookup],
|
|
) -> None:
|
|
# Instantiation
|
|
logger.debug(f"[processor] Instantiating classes...")
|
|
parser: Parser = select_parser(file_type, uprn_lookup)
|
|
mapper: Mapper = select_mapper(file_type)
|
|
persistence = ConditionPostgres()
|
|
|
|
logger.debug(f"[processor] Finished instantiating classes. Calling Parser...")
|
|
|
|
# Orchestration
|
|
raw_properties: List[Any] = parser.parse(file_stream)
|
|
|
|
logger.info(
|
|
f"[processor] Finished loading customer survey data for {len(raw_properties)} properties. Mapping..."
|
|
)
|
|
|
|
survey_year = datetime.now().year # TODO: get this from filepath or elsewhere
|
|
|
|
property_condition_surveys: List[PropertyConditionSurvey] = []
|
|
|
|
for p in raw_properties:
|
|
property_condition_surveys.append(
|
|
mapper.map_asset_conditions_for_property(p, survey_year)
|
|
)
|
|
|
|
logger.info(
|
|
f"[processor] Finished mapping {len(property_condition_surveys)} properties. Writing to database..."
|
|
)
|
|
|
|
persistence.bulk_insert_surveys(property_condition_surveys)
|
|
|
|
logger.info(f"[processor] Finished loading surveys to database")
|