Add the repository for the backup plan.

Only add, get_by_id and delete are implemented.
dev
KKlochko 4 months ago
parent 72f650fd64
commit 0abefda95a

@ -0,0 +1,37 @@
from typing import Optional
from tui_rsync.core.ports.orm import DatabaseManagerPort
from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
from .backup_plan_repository_port import BackupPlanRepositoryPort
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
class BackupPlanRepository(BackupPlanRepositoryPort):
def __init__(self, database_manager: DatabaseManagerPort):
self.databaseManager = database_manager
def add(self, backup_plan: BackupPlan):
model = BackupPlanDTO.to_model(backup_plan)
model.save(force_insert=True)
for destination in model.destinations:
destination.save(force_insert=True)
def get_by_id(self, uuid: UUID) -> Optional[BackupPlan]:
model = BackupPlanModel.get_or_none(BackupPlanModel.id == uuid.id)
if model is None:
return model
return BackupPlanDTO.to_domain(model)
def update(self, backup_plan: BackupPlan):
pass
def delete(self, uuid: UUID) -> bool:
deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()
return bool(deleted)

@ -0,0 +1,23 @@
from abc import ABC, abstractmethod
from typing import Optional
from tui_rsync.core.components.backup_plan.domain import BackupPlan
from tui_rsync.core.shared_kernel.components.common import UUID
class BackupPlanRepositoryPort(ABC):
@abstractmethod
def add(self, backup_plan: BackupPlan):
pass
@abstractmethod
def get_by_id(self, uuid: UUID) -> Optional[BackupPlan]:
pass
@abstractmethod
def update(self, backup_plan: BackupPlan):
pass
@abstractmethod
def delete(self, uuid: UUID) -> bool:
pass
Loading…
Cancel
Save