diff --git a/backend/condition/persistence/condition_postgres.py b/backend/condition/persistence/condition_postgres.py index 50b1f7be..b0ee018b 100644 --- a/backend/condition/persistence/condition_postgres.py +++ b/backend/condition/persistence/condition_postgres.py @@ -1,6 +1,10 @@ from typing import List -from backend.app.db.models.condition import PropertyConditionSurveyModel +from backend.app.db.models.condition import ( + AspectConditionModel, + ElementModel, + PropertyConditionSurveyModel, +) from backend.condition.domain.property_condition_survey import PropertyConditionSurvey @@ -13,4 +17,33 @@ class ConditionPostgres: def map_survey_to_model( survey: PropertyConditionSurvey, ) -> PropertyConditionSurveyModel: - raise NotImplementedError + survey_model = PropertyConditionSurveyModel( + uprn=survey.uprn, + date=survey.date, + source=survey.source, + elements=[], + ) + + for element in survey.elements: + element_model = ElementModel( + element_type=element.element_type, + element_instance=element.element_instance, + aspect_conditions=[], + ) + + for aspect in element.aspect_conditions: + aspect_model = AspectConditionModel( + aspect_type=aspect.aspect_type, + aspect_instance=aspect.aspect_instance, + value=aspect.value, + quantity=aspect.quantity, + install_date=aspect.install_date, + renewal_year=aspect.renewal_year, + comments=aspect.comments, + ) + + element_model.aspect_conditions.append(aspect_model) + + survey_model.elements.append(element_model) + + return survey_model diff --git a/backend/condition/tests/persistence/test_condition_postgres.py b/backend/condition/tests/persistence/test_condition_postgres.py index 4ed4423b..ca95eaaa 100644 --- a/backend/condition/tests/persistence/test_condition_postgres.py +++ b/backend/condition/tests/persistence/test_condition_postgres.py @@ -123,9 +123,32 @@ def test_map_survey_to_model() -> None: "element_type": ElementType.EXTERNAL_WALL, "element_instance": 1, "aspects": [ - {"value": "Pointed"}, - {"value": "Pointing"}, - {"value": "Tile Hung"}, + { + "aspect_instance": 1, + "value": "Pointed", + "quantity": 65, + "install_date": None, + "renewal_year": 2045, + "comments": None, + }, + { + "aspect_type": AspectType.FINISH, + "aspect_instance": 1, + "value": "Pointing", + "quantity": 1, + "install_date": None, + "renewal_year": 2069, + "comments": None, + }, + { + "aspect_type": AspectType.FINISH, + "aspect_instance": 2, + "value": "Tile Hung", + "quantity": 8, + "install_date": None, + "renewal_year": 2049, + "comments": None, + }, ], }, ],