On each notification the subscriber reads the zaak's reference (identificatie) through the ACL — the only code allowed to talk to ZGW (§8.1) — and persists it on the register_projection row and in the processed_notifications replay log. Storing it in the log keeps rebuild log-only (ADR-0008): no ACL/ZGW access on rebuild. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using EventSubscriber.Application;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Projection.ReadModel;
|
|
|
|
/// <summary>EF Core implementation of the projection store over <see cref="ProjectionDbContext"/>.</summary>
|
|
public sealed class EfProjectionStore(ProjectionDbContext db) : IProjectionStore
|
|
{
|
|
public async Task UpsertAsync(RegisterEntry entry, CancellationToken ct = default)
|
|
{
|
|
var row = await db.RegisterEntries.FindAsync([entry.Id], ct);
|
|
if (row is null)
|
|
{
|
|
db.RegisterEntries.Add(new RegisterEntryRow
|
|
{
|
|
Id = entry.Id,
|
|
Status = entry.Status,
|
|
Reference = entry.Reference,
|
|
Bsn = entry.Bsn,
|
|
NaamPlaceholder = entry.NaamPlaceholder,
|
|
});
|
|
}
|
|
else
|
|
{
|
|
row.Status = entry.Status;
|
|
row.Reference = entry.Reference;
|
|
row.Bsn = entry.Bsn;
|
|
row.NaamPlaceholder = entry.NaamPlaceholder;
|
|
}
|
|
|
|
await db.SaveChangesAsync(ct);
|
|
}
|
|
|
|
public async Task ClearAsync(CancellationToken ct = default)
|
|
=> await db.RegisterEntries.ExecuteDeleteAsync(ct);
|
|
|
|
public async Task<IReadOnlyList<RegisterEntry>> AllAsync(CancellationToken ct = default)
|
|
=> await db.RegisterEntries
|
|
.OrderBy(r => r.Id)
|
|
.Select(r => new RegisterEntry(r.Id, r.Status, Reference: r.Reference, Bsn: r.Bsn, NaamPlaceholder: r.NaamPlaceholder))
|
|
.ToListAsync(ct);
|
|
}
|