Island: Make upsert_node method public

Updating/inserting the node into the repository is required outside of repository itself.
This commit is contained in:
vakarisz 2022-10-05 14:33:00 +03:00
parent 73a8c14397
commit bbcdc1bef4
2 changed files with 10 additions and 2 deletions

View File

@ -25,6 +25,14 @@ class INodeRepository(ABC):
:raises StorageError: If an error occurs while attempting to upsert the Node :raises StorageError: If an error occurs while attempting to upsert the Node
""" """
@abstractmethod
def upsert_node(self, node: Node):
"""
Store the Node object in the repository by creating a new one or updating an existing one.
:param node: Node that will be saved
:raises StorageError: If an error occurs while attempting to upsert the Node
"""
@abstractmethod @abstractmethod
def get_nodes(self) -> Sequence[Node]: def get_nodes(self) -> Sequence[Node]:
""" """

View File

@ -34,7 +34,7 @@ class MongoNodeRepository(INodeRepository):
node, dst, communication_type node, dst, communication_type
) )
self._upsert_node(updated_node) self.upsert_node(updated_node)
@staticmethod @staticmethod
def _add_connection_to_node( def _add_connection_to_node(
@ -50,7 +50,7 @@ class MongoNodeRepository(INodeRepository):
return new_node return new_node
def _upsert_node(self, node: Node): def upsert_node(self, node: Node):
try: try:
result = self._nodes_collection.replace_one( result = self._nodes_collection.replace_one(
{SRC_FIELD_NAME: node.machine_id}, node.dict(simplify=True), upsert=True {SRC_FIELD_NAME: node.machine_id}, node.dict(simplify=True), upsert=True