Skip to content

Commit

Permalink
updated health builder
Browse files Browse the repository at this point in the history
  • Loading branch information
naman108 committed Mar 3, 2024
1 parent d40c83e commit deafe04
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Union
from digitalpy.core.domain.builder import Builder
from digitalpy.core.serialization.configuration.serialization_constants import Protocols

from ...configuration.health_constants import HEALTH
from ...domain.model.health import Health
from ...domain.model.contact import Contact
Expand All @@ -22,9 +24,9 @@ def build_empty_object(self, config_loader, *args, **kwargs): # pylint: disable
self.result = super()._create_model_object(
configuration, extended_domain={"Health": Health, "Contact": Contact})

def add_object_data(self, mapped_object: Union[bytes, DBHealth]):
def add_object_data(self, mapped_object: Union[bytes, DBHealth], protocol=None):
"""adds the data from the mapped object to the Health object """
if isinstance(mapped_object, bytes):
if protocol == Protocols.JSON and isinstance(mapped_object, bytes):
self._add_json_object_data(mapped_object)

elif isinstance(mapped_object, DBHealth):
Expand All @@ -34,6 +36,7 @@ def _add_json_object_data(self, json_object: bytes):
"""adds the data from the json object to the Health object """
self.request.set_value("model_object", self.result)
self.request.set_value("message", json_object)
self.request.set_value("protocol", Protocols.JSON)
self.execute_sub_action("deserialize")

def _add_db_object_data(self, db_object: DBHealth):
Expand All @@ -47,6 +50,7 @@ def _add_db_object_data(self, db_object: DBHealth):
self.result.StepsCount = db_object.StepsCount
self.result.SleepData = db_object.SleepData
self.result.StressLevel = db_object.StressLevel
self.result.bodyOxygen = db_object.bodyOxygen

def get_result(self):
"""gets the result of the builder"""
Expand Down

0 comments on commit deafe04

Please sign in to comment.