mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-12 17:57:43 +00:00
Update the configuration to use queries and commands.
This commit is contained in:
+4
@@ -1,7 +1,11 @@
|
||||
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
||||
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
|
||||
|
||||
|
||||
class RemoveAllBackupBackupPlansCommand:
|
||||
def __init__(self, database_manager: DatabaseManagerPort):
|
||||
self.databaseManager = database_manager
|
||||
|
||||
def execute(self) -> bool:
|
||||
rows = BackupPlanModel.delete().execute()
|
||||
rows = DestinationModel.delete().execute() + rows
|
||||
|
||||
+4
@@ -1,8 +1,12 @@
|
||||
from tui_rsync.core.ports.orm import DatabaseManagerPort
|
||||
from tui_rsync.infrastructure.orm.dto.dtos import BackupPlanDTO
|
||||
|
||||
from tui_rsync.infrastructure.orm.models import BackupPlanModel
|
||||
|
||||
|
||||
class GetAllBackupBackupPlansQuery:
|
||||
def __init__(self, database_manager: DatabaseManagerPort):
|
||||
self.databaseManager = database_manager
|
||||
|
||||
def execute(self):
|
||||
return (BackupPlanDTO.to_domain(model) for model in BackupPlanModel.select().iterator())
|
||||
@@ -1,3 +1,5 @@
|
||||
from .user_data_paths import UserDataPaths
|
||||
from .current_configuration import CurrentConfiguration
|
||||
from .configuration import Configuration
|
||||
|
||||
__all__ = ['UserDataPaths']
|
||||
__all__ = ['UserDataPaths', 'CurrentConfiguration', 'Configuration']
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from injector import singleton, inject, Injector, Module, provider
|
||||
|
||||
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
|
||||
from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupBackupPlansQuery
|
||||
from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort
|
||||
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
||||
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||
@@ -29,3 +31,13 @@ class Configuration(Module):
|
||||
@singleton
|
||||
def provide_backup_plan_service(self, backup_plan_repository: BackupPlanRepositoryPort) -> BackupPlanService:
|
||||
return BackupPlanService(backup_plan_repository)
|
||||
|
||||
@provider
|
||||
@singleton
|
||||
def provide_remove_all_backup_backup_plans_command(self, database_manager: DatabaseManagerPort) -> RemoveAllBackupBackupPlansCommand:
|
||||
return RemoveAllBackupBackupPlansCommand(database_manager)
|
||||
|
||||
@provider
|
||||
@singleton
|
||||
def provide_get_all_backup_backup_plans_query(self, database_manager: DatabaseManagerPort) -> GetAllBackupBackupPlansQuery:
|
||||
return GetAllBackupBackupPlansQuery(database_manager)
|
||||
|
||||
@@ -24,7 +24,7 @@ import typer
|
||||
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||
from tui_rsync.core.components.backup_plan.domain import BackupPlan, Source, Destination
|
||||
from tui_rsync.core.shared_kernel.components.common import Label
|
||||
from tui_rsync.infrastructure.configuration.current_configuration import CurrentConfiguration
|
||||
from tui_rsync.infrastructure.configuration import CurrentConfiguration
|
||||
|
||||
|
||||
console = Console()
|
||||
|
||||
@@ -21,11 +21,9 @@ from rich.console import Console
|
||||
import typer
|
||||
|
||||
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
|
||||
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
||||
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||
from tui_rsync.core.shared_kernel.components.common import UUID
|
||||
from tui_rsync.infrastructure.configuration import UserDataPaths
|
||||
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
|
||||
from tui_rsync.infrastructure.configuration import CurrentConfiguration
|
||||
|
||||
console = Console()
|
||||
remove_backup_plan = typer.Typer()
|
||||
@@ -43,9 +41,7 @@ def one(
|
||||
[red b]Remove[/] an [yellow]existing backup plan[/].
|
||||
"""
|
||||
|
||||
db = SqliteDatabaseManager(UserDataPaths())
|
||||
repository = BackupPlanRepository(db)
|
||||
service = BackupPlanService(repository)
|
||||
service: BackupPlanService = CurrentConfiguration.get(BackupPlanService)
|
||||
|
||||
if id is None:
|
||||
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
|
||||
@@ -66,8 +62,8 @@ def all():
|
||||
[red b]Remove[/] [yellow] all existing backup plans[/].
|
||||
"""
|
||||
|
||||
db = SqliteDatabaseManager(UserDataPaths())
|
||||
removed = RemoveAllBackupBackupPlansCommand().execute()
|
||||
command: RemoveAllBackupBackupPlansCommand = CurrentConfiguration.get(RemoveAllBackupBackupPlansCommand)
|
||||
removed = command.execute()
|
||||
|
||||
if removed:
|
||||
console.print(f"Removed all backup plans.")
|
||||
|
||||
@@ -20,13 +20,11 @@
|
||||
from rich.console import Console
|
||||
import typer
|
||||
|
||||
from tui_rsync.core.components.backup_plan.application.Queries import GetAllBackupBackupPlansQuery
|
||||
from tui_rsync.core.components.backup_plan.application.queries import GetAllBackupBackupPlansQuery
|
||||
|
||||
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
||||
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||
from tui_rsync.core.shared_kernel.components.common import UUID
|
||||
from tui_rsync.infrastructure.configuration import UserDataPaths
|
||||
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
|
||||
from tui_rsync.infrastructure.configuration import CurrentConfiguration
|
||||
from tui_rsync.user_interface.cli.components.backup_plan.formating import BackupPlanFormat
|
||||
|
||||
console = Console()
|
||||
@@ -45,9 +43,7 @@ def one(
|
||||
[green b]Show[/] an [yellow]existing backup plan by the id[/].
|
||||
"""
|
||||
|
||||
db = SqliteDatabaseManager(UserDataPaths())
|
||||
repository = BackupPlanRepository(db)
|
||||
service = BackupPlanService(repository)
|
||||
service: BackupPlanService = CurrentConfiguration.get(BackupPlanService)
|
||||
|
||||
if id is None:
|
||||
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
|
||||
@@ -68,8 +64,7 @@ def all():
|
||||
[green b]Show[/] [yellow]all existing backup plans[/].
|
||||
"""
|
||||
|
||||
db = SqliteDatabaseManager(UserDataPaths())
|
||||
query = GetAllBackupBackupPlansQuery()
|
||||
query = CurrentConfiguration.get(GetAllBackupBackupPlansQuery)
|
||||
|
||||
for backup_plan in query.execute():
|
||||
console.print(BackupPlanFormat.format(backup_plan))
|
||||
|
||||
Reference in New Issue
Block a user