-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessorRepository.cs
More file actions
38 lines (27 loc) · 1.17 KB
/
Copy pathProcessorRepository.cs
File metadata and controls
38 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using InvvardDev.Ifttt.Contracts;
using InvvardDev.Ifttt.Models.Trigger;
namespace InvvardDev.Ifttt.Services;
internal class ProcessorRepository : IProcessorRepository
{
private readonly Dictionary<string, ProcessorTree> processors = new();
public Task AddProcessor(ProcessorTree processorTree)
{
processors.Add(processorTree.Key, processorTree);
return Task.CompletedTask;
}
public Task UpdateProcessor(ProcessorTree processorTree)
{
processors[processorTree.Key] = processorTree;
return Task.CompletedTask;
}
public Task<bool> Exists(string key)
=> Task.FromResult(processors.ContainsKey(key));
public Task<ProcessorTree?> GetProcessorByKey(string key)
=> Task.FromResult(processors.GetValueOrDefault(key));
public Task<IEnumerable<ProcessorTree>> FilterProcessors(Func<ProcessorTree, bool> predicate)
=> Task.FromResult(GetProcessorsTrees().Where(predicate));
public Task<IEnumerable<ProcessorTree>> GetAllProcessors()
=> Task.FromResult(GetProcessorsTrees());
private IEnumerable<ProcessorTree> GetProcessorsTrees()
=> processors.Select(p => p.Value);
}