Update the configuration to use queries and commands.

This commit is contained in:
2025-01-11 17:52:06 +02:00
parent a0846b93a1
commit 70f60ff715
8 changed files with 32 additions and 19 deletions
@@ -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))