Update the remove all backup plans command.

Refactor the commands names.
Add the service to remove all plans.
Add tests for remove all command.
This commit is contained in:
2025-01-28 10:40:23 +02:00
parent 76e555aefb
commit 2874dc76ad
11 changed files with 75 additions and 25 deletions
@@ -1,5 +1,5 @@
from .remove_all_backup_plans_command import RemoveAllBackupBackupPlansCommand
from .remove_backup_plan_destinations_command import RemoveBackupBackupPlanDestinationsCommand
from .remove_backup_plan_command import RemoveBackupBackupPlanCommand
from .remove_all_backup_plans_command import RemoveAllBackupPlansCommand
from .remove_backup_plan_destinations_command import RemoveBackupPlanDestinationsCommand
from .remove_backup_plan_command import RemoveBackupPlanCommand
__all__ = ['RemoveAllBackupBackupPlansCommand', 'RemoveBackupBackupPlanCommand', 'RemoveBackupBackupPlanDestinationsCommand']
__all__ = ['RemoveAllBackupPlansCommand', 'RemoveBackupPlanCommand', 'RemoveBackupPlanDestinationsCommand']
@@ -2,7 +2,7 @@ from tui_rsync.core.ports.orm import DatabaseManagerPort
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
class RemoveAllBackupBackupPlansCommand:
class RemoveAllBackupPlansCommand:
def __init__(self, database_manager: DatabaseManagerPort):
self.databaseManager = database_manager
@@ -4,7 +4,7 @@ from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException
from tui_rsync.infrastructure.orm.models import DestinationModel, BackupPlanModel
class RemoveBackupBackupPlanCommand:
class RemoveBackupPlanCommand:
def __init__(self, database_manager: DatabaseManagerPort):
self.databaseManager = database_manager
@@ -3,7 +3,7 @@ from tui_rsync.core.shared_kernel.components.common import UUID
from tui_rsync.infrastructure.orm.models import DestinationModel
class RemoveBackupBackupPlanDestinationsCommand:
class RemoveBackupPlanDestinationsCommand:
def __init__(self, database_manager: DatabaseManagerPort):
self.databaseManager = database_manager
@@ -8,7 +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
from ..commands import RemoveBackupBackupPlanDestinationsCommand, RemoveBackupBackupPlanCommand
from ..commands import RemoveBackupPlanDestinationsCommand, RemoveBackupPlanCommand
from ..queries import GetBackupPlanByIdQuery
@@ -30,7 +30,7 @@ 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)
remove_backup_plan_destinations_command = RemoveBackupBackupPlanDestinationsCommand(self.databaseManager)
remove_backup_plan_destinations_command = RemoveBackupPlanDestinationsCommand(self.databaseManager)
model.label = updated_model.label
model.source = updated_model.source
@@ -42,5 +42,5 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
destination.save(force_insert=True)
def delete(self, uuid: UUID) -> bool:
command = RemoveBackupBackupPlanCommand(self.databaseManager)
command = RemoveBackupPlanCommand(self.databaseManager)
return command.execute(uuid)
@@ -1,5 +1,11 @@
from .backup_plan_service import BackupPlanService
from .get_all_backup_plans_service import GetAllBackupPlansService
from .get_backup_plan_count_service import GetBackupPlanCountService
from .remove_all_backup_plans_service import RemoveAllBackupPlansService
__all__ = ['BackupPlanService', 'GetAllBackupPlansService', 'GetBackupPlanCountService']
__all__ = [
'BackupPlanService',
'GetAllBackupPlansService',
'GetBackupPlanCountService',
'RemoveAllBackupPlansService',
]
@@ -0,0 +1,9 @@
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupPlansCommand
class RemoveAllBackupPlansService:
def __init__(self, remove_all_backup_plan_command: RemoveAllBackupPlansCommand):
self.remove_all_backup_plan_command = remove_all_backup_plan_command
def remove_all(self) -> bool:
return self.remove_all_backup_plan_command.execute()