From f9b49c69bd29c804e2a0749488db0d1a844d6714 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 21 Jan 2025 21:56:53 +0200 Subject: [PATCH] Update the repository and service to implement the update action. --- .../repository/backup_plan_repository.py | 14 +++++++++++++- .../application/services/backup_plan_service.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tui_rsync/core/components/backup_plan/application/repository/backup_plan_repository.py b/tui_rsync/core/components/backup_plan/application/repository/backup_plan_repository.py index fc26c8d..2d323d1 100644 --- a/tui_rsync/core/components/backup_plan/application/repository/backup_plan_repository.py +++ b/tui_rsync/core/components/backup_plan/application/repository/backup_plan_repository.py @@ -8,6 +8,7 @@ from tui_rsync.core.components.backup_plan.domain import BackupPlan from tui_rsync.core.shared_kernel.components.common import UUID from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel +from ..commands import RemoveBackupBackupPlanDestinationsCommand class BackupPlanRepository(BackupPlanRepositoryPort): @@ -30,7 +31,18 @@ class BackupPlanRepository(BackupPlanRepositoryPort): return BackupPlanDTO.to_domain(model) def update(self, backup_plan: BackupPlan): - pass + updated_model = BackupPlanDTO.to_model(backup_plan) + model = BackupPlanModel.get_or_none(BackupPlanModel.id == updated_model.id) + remove_backup_plan_destinations_command = RemoveBackupBackupPlanDestinationsCommand(self.databaseManager) + + model.label = updated_model.label + model.source = updated_model.source + + remove_backup_plan_destinations_command.execute(backup_plan.id) + + model.save() + for destination in updated_model.destinations: + destination.save(force_insert=True) def delete(self, uuid: UUID) -> bool: deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute() diff --git a/tui_rsync/core/components/backup_plan/application/services/backup_plan_service.py b/tui_rsync/core/components/backup_plan/application/services/backup_plan_service.py index e347f71..9322422 100644 --- a/tui_rsync/core/components/backup_plan/application/services/backup_plan_service.py +++ b/tui_rsync/core/components/backup_plan/application/services/backup_plan_service.py @@ -17,7 +17,7 @@ class BackupPlanService: return self.backup_plan_repository.get_by_id(uuid) def update(self, backup_plan: BackupPlan): - pass + return self.backup_plan_repository.update(backup_plan) def delete(self, uuid: UUID) -> bool: return self.backup_plan_repository.delete(uuid)