Update the repository and service to implement the update action.

dev
KKlochko 3 months ago
parent bc22e8a8bd
commit f9b49c69bd

@ -8,6 +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.core.shared_kernel.components.common import UUID
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
from ..commands import RemoveBackupBackupPlanDestinationsCommand
class BackupPlanRepository(BackupPlanRepositoryPort): class BackupPlanRepository(BackupPlanRepositoryPort):
@ -30,7 +31,18 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
return BackupPlanDTO.to_domain(model) return BackupPlanDTO.to_domain(model)
def update(self, backup_plan: BackupPlan): def update(self, backup_plan: BackupPlan):
pass 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)
model.label = updated_model.label
model.source = updated_model.source
remove_backup_plan_destinations_command.execute(backup_plan.id)
model.save()
for destination in updated_model.destinations:
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() deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()

@ -17,7 +17,7 @@ class BackupPlanService:
return self.backup_plan_repository.get_by_id(uuid) return self.backup_plan_repository.get_by_id(uuid)
def update(self, backup_plan: BackupPlan): def update(self, backup_plan: BackupPlan):
pass return self.backup_plan_repository.update(backup_plan)
def delete(self, uuid: UUID) -> bool: def delete(self, uuid: UUID) -> bool:
return self.backup_plan_repository.delete(uuid) return self.backup_plan_repository.delete(uuid)

Loading…
Cancel
Save