35 lines
1.5 KiB
C#
35 lines
1.5 KiB
C#
using System.Collections.Concurrent;
|
|
using Big.Application;
|
|
using Big.Domain;
|
|
|
|
namespace Big.Infrastructure;
|
|
|
|
/// <summary>
|
|
/// In-memory <see cref="IRegistrationStore"/> for the minimal slice (ADR-0009). The walking
|
|
/// skeleton's read path is the projection (S-06), not this store, so durable domain persistence is a
|
|
/// documented follow-up. Registered as a singleton so the submit endpoint and the worker share it.
|
|
/// </summary>
|
|
public sealed class InMemoryRegistrationStore : IRegistrationStore
|
|
{
|
|
private readonly ConcurrentDictionary<RegistrationId, Registration> _byId = new();
|
|
|
|
public Task SaveAsync(Registration registration, CancellationToken ct = default)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(registration);
|
|
_byId[registration.Id] = registration;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<Registration?> GetAsync(RegistrationId id, CancellationToken ct = default)
|
|
=> Task.FromResult(_byId.GetValueOrDefault(id));
|
|
|
|
public Task<Registration?> FindOpenByBsnAsync(string bsn, CancellationToken ct = default)
|
|
=> Task.FromResult(_byId.Values.FirstOrDefault(r =>
|
|
r.Bsn == bsn && r.Status is RegistrationStatus.Ingediend or RegistrationStatus.InBehandeling));
|
|
|
|
public Task<IReadOnlyList<Registration>> FindDueForHerregistratieReminderAsync(
|
|
DateTimeOffset asOf, CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<Registration>>(
|
|
_byId.Values.Where(r => r.HerregistratieReminderDue(asOf)).ToList());
|
|
}
|