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()
@@ -1,10 +1,10 @@
from injector import singleton, Module, provider
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupPlansCommand
from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupPlansQuery, GetBackupPlanCountQuery
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository
from tui_rsync.core.components.backup_plan.application.services import GetBackupPlanCountService, \
GetAllBackupPlansService
GetAllBackupPlansService, RemoveAllBackupPlansService
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
from tui_rsync.core.ports.configuration import UserDataPathsPort
from tui_rsync.core.ports.orm import DatabaseManagerPort
@@ -39,8 +39,13 @@ class Configuration(Module):
@provider
@singleton
def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand:
return RemoveAllBackupBackupPlansCommand(database_manager)
def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupPlansCommand:
return RemoveAllBackupPlansCommand(database_manager)
@provider
@singleton
def provide_remove_all_backup_plans_service(self, command: RemoveAllBackupPlansCommand) -> RemoveAllBackupPlansService:
return RemoveAllBackupPlansService(command)
@provider
@singleton
@@ -1,10 +1,10 @@
from injector import singleton, Module, provider
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupPlansCommand
from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupPlansQuery, GetBackupPlanCountQuery
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort, BackupPlanRepository
from tui_rsync.core.components.backup_plan.application.services import GetBackupPlanCountService, \
GetAllBackupPlansService
GetAllBackupPlansService, RemoveAllBackupPlansService
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
from tui_rsync.core.ports.configuration import UserDataPathsPort
from tui_rsync.core.ports.orm import DatabaseManagerPort
@@ -39,8 +39,13 @@ class TestingConfiguration(Module):
@provider
@singleton
def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand:
return RemoveAllBackupBackupPlansCommand(database_manager)
def provide_remove_all_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupPlansCommand:
return RemoveAllBackupPlansCommand(database_manager)
@provider
@singleton
def provide_remove_all_backup_plans_service(self, command: RemoveAllBackupPlansCommand) -> RemoveAllBackupPlansService:
return RemoveAllBackupPlansService(command)
@provider
@singleton
@@ -20,7 +20,7 @@
from rich.console import Console
import typer
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
from tui_rsync.core.components.backup_plan.application.services import RemoveAllBackupPlansService
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
from tui_rsync.core.shared_kernel.components.common import UUID
from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException
@@ -57,10 +57,9 @@ def all():
[red b]Remove[/] [yellow] all existing backup plans[/].
"""
command: RemoveAllBackupBackupPlansCommand = CurrentConfiguration.get(RemoveAllBackupBackupPlansCommand)
removed = command.execute()
service: RemoveAllBackupPlansService = CurrentConfiguration.get(RemoveAllBackupPlansService)
if removed:
console.print(f"Removed all backup plans.")
if service.remove_all():
console.print("All backup plans removed.")
else:
console.print(f"Nothing to remove. No backup plans.")
console.print("Nothing to remove. No backup plans.")