mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-20 05:37:43 +00:00
Add the query exception and refactor get_by_id.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from .get_all_backup_plans_query import GetAllBackupBackupPlansQuery
|
||||
from .get_backup_plan_by_id_query import GetBackupBackupPlanByIdQuery
|
||||
|
||||
__all__ = ['GetAllBackupBackupPlansQuery']
|
||||
__all__ = ['GetAllBackupBackupPlansQuery', 'GetBackupBackupPlanByIdQuery']
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
from tui_rsync.core.components.backup_plan.domain import BackupPlan
|
||||
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.query_exception import QueryException
|
||||
from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
|
||||
|
||||
from tui_rsync.infrastructure.orm.models import BackupPlanModel
|
||||
|
||||
|
||||
class GetBackupBackupPlanByIdQuery:
|
||||
def __init__(self, database_manager: DatabaseManagerPort):
|
||||
self.databaseManager = database_manager
|
||||
|
||||
def execute(self, uuid: UUID) -> BackupPlan:
|
||||
model = BackupPlanModel.get_or_none(BackupPlanModel.id == uuid.id)
|
||||
|
||||
if model is None:
|
||||
raise QueryException("The backup plan was not found.")
|
||||
|
||||
return BackupPlanDTO.to_domain(model)
|
||||
+4
-7
@@ -9,6 +9,7 @@ from tui_rsync.core.shared_kernel.components.common import UUID
|
||||
|
||||
from tui_rsync.infrastructure.orm.models import BackupPlanModel
|
||||
from ..commands import RemoveBackupBackupPlanDestinationsCommand, RemoveBackupBackupPlanCommand
|
||||
from ..queries import GetBackupBackupPlanByIdQuery
|
||||
|
||||
|
||||
class BackupPlanRepository(BackupPlanRepositoryPort):
|
||||
@@ -22,13 +23,9 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
|
||||
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 get_by_id(self, uuid: UUID) -> BackupPlan:
|
||||
query = GetBackupBackupPlanByIdQuery(self.databaseManager)
|
||||
return query.execute(uuid)
|
||||
|
||||
def update(self, backup_plan: BackupPlan):
|
||||
updated_model = BackupPlanDTO.to_model(backup_plan)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from . import AppException
|
||||
|
||||
|
||||
class QueryException(AppException):
|
||||
"""Query failed."""
|
||||
pass
|
||||
Reference in New Issue
Block a user