mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-09-13 08:57:43 +00:00
Update to refactor the delete action.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from .remove_all_backup_plans_command import RemoveAllBackupBackupPlansCommand
|
from .remove_all_backup_plans_command import RemoveAllBackupBackupPlansCommand
|
||||||
from .remove_backup_plan_destinations_command import RemoveBackupBackupPlanDestinationsCommand
|
from .remove_backup_plan_destinations_command import RemoveBackupBackupPlanDestinationsCommand
|
||||||
|
from .remove_backup_plan_command import RemoveBackupBackupPlanCommand
|
||||||
|
|
||||||
__all__ = ['RemoveAllBackupBackupPlansCommand', 'RemoveBackupBackupPlanDestinationsCommand']
|
__all__ = ['RemoveAllBackupBackupPlansCommand', 'RemoveBackupBackupPlanCommand', 'RemoveBackupBackupPlanDestinationsCommand']
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
||||||
|
from tui_rsync.core.shared_kernel.components.common import UUID
|
||||||
|
from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException
|
||||||
|
from tui_rsync.infrastructure.orm.models import DestinationModel, BackupPlanModel
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveBackupBackupPlanCommand:
|
||||||
|
def __init__(self, database_manager: DatabaseManagerPort):
|
||||||
|
self.databaseManager = database_manager
|
||||||
|
|
||||||
|
def execute(self, uuid: UUID) -> bool:
|
||||||
|
deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()
|
||||||
|
deleted = DestinationModel.delete().where(DestinationModel.source == uuid.id).execute() | deleted
|
||||||
|
|
||||||
|
if deleted == 0:
|
||||||
|
raise CommandException("Failed to delete the backup plan, because it doesn't exist.")
|
||||||
|
|
||||||
|
return True
|
||||||
+4
-10
@@ -1,15 +1,14 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
||||||
from tui_rsync.core.shared_kernel.ports.Exceptions import CommandException
|
|
||||||
from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
|
from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
|
||||||
from .backup_plan_repository_port import BackupPlanRepositoryPort
|
from .backup_plan_repository_port import BackupPlanRepositoryPort
|
||||||
|
|
||||||
from tui_rsync.core.components.backup_plan.domain import BackupPlan
|
from tui_rsync.core.components.backup_plan.domain import BackupPlan
|
||||||
from tui_rsync.core.shared_kernel.components.common import UUID
|
from tui_rsync.core.shared_kernel.components.common import UUID
|
||||||
|
|
||||||
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
|
from tui_rsync.infrastructure.orm.models import BackupPlanModel
|
||||||
from ..commands import RemoveBackupBackupPlanDestinationsCommand
|
from ..commands import RemoveBackupBackupPlanDestinationsCommand, RemoveBackupBackupPlanCommand
|
||||||
|
|
||||||
|
|
||||||
class BackupPlanRepository(BackupPlanRepositoryPort):
|
class BackupPlanRepository(BackupPlanRepositoryPort):
|
||||||
@@ -46,10 +45,5 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
|
|||||||
destination.save(force_insert=True)
|
destination.save(force_insert=True)
|
||||||
|
|
||||||
def delete(self, uuid: UUID) -> bool:
|
def delete(self, uuid: UUID) -> bool:
|
||||||
deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()
|
command = RemoveBackupBackupPlanCommand(self.databaseManager)
|
||||||
deleted = DestinationModel.delete().where(DestinationModel.source == uuid.id).execute() | deleted
|
return command.execute(uuid)
|
||||||
|
|
||||||
if deleted == 0:
|
|
||||||
raise CommandException("Failed to delete the backup plan, because it doesn't exist.")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|||||||
Reference in New Issue
Block a user