mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
map survey to model 🟩
This commit is contained in:
parent
47b416e5cb
commit
c1d480b87d
2 changed files with 61 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue