Update the repository to use exception for the delete action.

This commit is contained in:
2025-01-26 14:28:56 +02:00
parent 769edabbd3
commit cae4ce50c5
4 changed files with 19 additions and 15 deletions
@@ -1,6 +1,7 @@
from typing import Optional
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 .backup_plan_repository_port import BackupPlanRepositoryPort
@@ -47,4 +48,8 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
def delete(self, uuid: UUID) -> bool:
deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()
deleted = DestinationModel.delete().where(DestinationModel.source == uuid.id).execute() | deleted
return bool(deleted)
if deleted == 0:
raise CommandException("Failed to delete the backup plan, because it doesn't exist.")
return True