Skip to content

Commit 9f1b19c

Browse files
committed
feat: creations, readings and deletions of Tasks are done for both the Backend repository and the file system one
1 parent f622c48 commit 9f1b19c

4 files changed

Lines changed: 22 additions & 12 deletions

File tree

Desktop.Tests/UnitTests/TaskListViewModelTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32
using Desktop.Project;
43
using Desktop.Tasks;
54
using Desktop.Tests.TestAPI;
@@ -27,7 +26,7 @@ public async Task TasksPopulation_IsIdempotent()
2726
private static TaskListViewModel TaskListViewModel(InMemoryTaskRepository taskRepository)
2827
{
2928
return new TaskListViewModel(
30-
taskRepository,
31-
new TaskCreationViewModel(taskRepository));
29+
[taskRepository],
30+
new TaskCreationViewModel([taskRepository]));
3231
}
3332
}

Desktop/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ protected override void OnStartup(StartupEventArgs e)
2727
services.AddSingleton<TaskCreation>();
2828
services.AddTransient<TaskCreationViewModel>();
2929
services.AddTransient<TaskListViewModel>();
30+
services.AddSingleton<ITaskRepository, FileSystemTaskRepository>();
3031
services.AddBackendTaskRepository(Config);
3132

3233
var serviceProvider = services.BuildServiceProvider();

Desktop/Project/TaskListViewModel.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ namespace Desktop.Project;
1010

1111
public class TaskListViewModel : ViewModelBase
1212
{
13-
private readonly ITaskRepository taskRepository;
13+
private readonly IEnumerable<ITaskRepository> taskRepositories;
1414
public ObservableCollection<Task> Tasks { get; } = [];
1515

1616
public Func<TaskCreationViewModel, IShowable> TaskCreationViewCreator { get; set; }
1717

1818
public TaskListViewModel(
19-
ITaskRepository taskRepository,
19+
IEnumerable<ITaskRepository> taskRepositories,
2020
TaskCreationViewModel taskCreationViewModel)
2121
{
22-
this.taskRepository = taskRepository;
22+
this.taskRepositories = taskRepositories;
2323

2424
Add = new RelayCommand(() =>
2525
{
@@ -34,7 +34,9 @@ public TaskListViewModel(
3434
Delete = new RelayCommand<Task>(taskToRemove =>
3535
{
3636
Tasks.Remove(taskToRemove!);
37-
taskRepository.Delete(taskToRemove!);
37+
38+
foreach (var repository in this.taskRepositories)
39+
repository.Delete(taskToRemove!);
3840
});
3941
}
4042

@@ -47,7 +49,10 @@ public void PopulateTasks()
4749
Tasks.Clear();
4850

4951
// TODO: load this async and deferred from the ctor.
50-
var retrievedTasks = SystemTask.Run(taskRepository.All).Result;
52+
var retrievedTasks = SystemTask.Run(() => SystemTask
53+
.WhenAll(taskRepositories.Select(x => x.All())))
54+
.Result
55+
.SelectMany(x => x);
5156
foreach (var task in retrievedTasks)
5257
Tasks.Add(task);
5358
}

Desktop/Tasks/TaskCreationViewModel.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@ namespace Desktop.Tasks;
66

77
public class TaskCreationViewModel : ViewModelBase
88
{
9-
public TaskCreationViewModel(ITaskRepository taskRepository)
9+
public TaskCreationViewModel(IEnumerable<ITaskRepository> taskRepositories)
1010
{
1111
SaveTask =
12-
new RelayCommand<(ICloseable, string, string)>((args) =>
12+
new RelayCommand<(ICloseable, string, string)>(args =>
1313
{
1414
var (closeable, taskName, taskDescription) = args;
1515

1616
CreatedTask = new Task(taskName, taskDescription);
17-
taskRepository.Save(CreatedTask);
17+
18+
foreach (var repository in taskRepositories)
19+
{
20+
repository.Save(CreatedTask);
21+
}
22+
1823
closeable!.Close();
1924
});
2025
}

0 commit comments

Comments
 (0)