From 2438dead078f9569358c6d0795e60b03f0ba18e5 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 29 Jan 2025 21:08:52 +0200 Subject: [PATCH] Update the replace command to show responses. --- .../application/repository/backup_plan_repository.py | 5 ++++- .../cli/components/backup_plan/update_backup_plan.py | 8 +++++++- 2 files changed, 11 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 525288b..56930bb 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 @@ -29,7 +29,10 @@ class BackupPlanRepository(BackupPlanRepositoryPort): def update(self, backup_plan: BackupPlan): updated_model = BackupPlanDTO.to_model(backup_plan) - model = BackupPlanModel.get_or_none(BackupPlanModel.id == updated_model.id) + query = GetBackupPlanByIdQuery(self.databaseManager) + + old_plan = query.execute(backup_plan.id) + model = BackupPlanDTO.to_model(old_plan) remove_backup_plan_destinations_command = RemoveBackupPlanDestinationsCommand(self.databaseManager) model.label = updated_model.label diff --git a/tui_rsync/user_interface/cli/components/backup_plan/update_backup_plan.py b/tui_rsync/user_interface/cli/components/backup_plan/update_backup_plan.py index 6b45100..6c9c86d 100644 --- a/tui_rsync/user_interface/cli/components/backup_plan/update_backup_plan.py +++ b/tui_rsync/user_interface/cli/components/backup_plan/update_backup_plan.py @@ -24,14 +24,18 @@ import typer from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService from tui_rsync.core.components.backup_plan.domain import BackupPlan, Source, Destination, BackupPlanId from tui_rsync.core.shared_kernel.components.common import Label +from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException +from tui_rsync.core.shared_kernel.ports.Exceptions.query_exception import QueryException from tui_rsync.infrastructure.configuration import CurrentConfiguration - +from tui_rsync.user_interface.cli.shared_kernel.components.errors.applications.exceptions import catch_exception console = Console() update_backup_plan = typer.Typer() @update_backup_plan.command() +@catch_exception(CommandException, 1) +@catch_exception(QueryException, 1) def replace( id: str = typer.Option( None, "--id", "-i", @@ -65,3 +69,5 @@ def replace( plan = BackupPlan(id=BackupPlanId(id), label=Label(label), source=Source(source), destinations=[Destination(path) for path in destinations]) service.update(plan) + console.print("The backup plan updated.") +