mirror of https://gitlab.com/KKlochko/tui-rsync
parent
b10726796d
commit
72f650fd64
@ -0,0 +1,3 @@
|
||||
from .dtos import BackupPlanDTO
|
||||
|
||||
__all__ = ['BackupPlanDTO']
|
@ -0,0 +1,34 @@
|
||||
from peewee import *
|
||||
|
||||
from tui_rsync.core.components.backup_plan.domain import BackupPlan, Destination, Source, BackupPlanId
|
||||
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
|
||||
|
||||
|
||||
class BackupPlanDTO:
|
||||
@staticmethod
|
||||
def to_domain(model: BackupPlanModel) -> BackupPlan:
|
||||
return BackupPlan(
|
||||
id=BackupPlanId(model.id),
|
||||
label=model.label,
|
||||
source=Source(model.source),
|
||||
destinations=list(map(lambda destination: Destination(destination.path), model.destinations)),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_model(entity: BackupPlan) -> BackupPlanModel:
|
||||
model = BackupPlanModel(
|
||||
id=entity.id.id,
|
||||
label=entity.label,
|
||||
source=entity.source.path,
|
||||
destinations=[],
|
||||
)
|
||||
|
||||
for destination in entity.destinations:
|
||||
model.destinations.append(
|
||||
DestinationModel(
|
||||
source=model,
|
||||
path=destination.path
|
||||
)
|
||||
)
|
||||
|
||||
return model
|
Loading…
Reference in new issue