-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathUserInMemoryRepository.cs
More file actions
42 lines (35 loc) · 1.2 KB
/
Copy pathUserInMemoryRepository.cs
File metadata and controls
42 lines (35 loc) · 1.2 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
39
40
41
42
namespace BuberDinner.Infrastructure.Persistence.Memory;
using BuberDinner.Application.Abstractions.Persistence;
using BuberDinner.Domain.User.Entities;
using System.Collections.Generic;
using System.Linq;
internal class UserInMemoryRepository : IRepository<User>
{
private static readonly List<User> s_users = new();
private static readonly object s_lock = new();
public IEnumerable<User> GetAll(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public ValueTask Add(User user, CancellationToken cancellationToken)
{
lock (s_lock)
s_users.Add(user);
return ValueTask.CompletedTask;
}
public ValueTask Update(User entity, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public ValueTask Delete(User entity, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public ValueTask<Maybe<User>> FindById(string id, CancellationToken cancellationToken)
{
User? user;
lock (s_lock)
user = s_users.SingleOrDefault(u => u.Id == id);
return ValueTask.FromResult(Maybe.From(user));
}
}