feat(event-subscriber): project zaak-created notifications into the read projection (refs #7)
Implement NotificationProjector: a zaken/zaak/create notification records the delivery in the notification log (atomic record-or-skip for idempotency, §8.6) and upserts an INGEDIEND projection row keyed by zaak id; other channels/actions are ignored. Rebuild clears the projection and replays the log — no OpenZaak access needed (§8.1). bsn/naam are deferred (ADR-0008). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,12 +8,31 @@ namespace EventSubscriber.Application;
|
|||||||
public sealed class NotificationProjector(INotificationLog log, IProjectionStore store)
|
public sealed class NotificationProjector(INotificationLog log, IProjectionStore store)
|
||||||
{
|
{
|
||||||
/// <summary>Handle one inbound notification. Ignores anything that is not a zaak-created event.</summary>
|
/// <summary>Handle one inbound notification. Ignores anything that is not a zaak-created event.</summary>
|
||||||
public Task HandleAsync(Notification notification, CancellationToken ct = default)
|
public async Task HandleAsync(Notification notification, CancellationToken ct = default)
|
||||||
// RED: not yet implemented — the smallest change to make the tests pass comes next.
|
{
|
||||||
=> Task.CompletedTask;
|
if (!notification.IsZaakCreated)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var recorded = new RecordedNotification(notification.IdempotencyKey, notification.Actie, notification.ZaakId);
|
||||||
|
|
||||||
|
// Atomic record-or-skip: a duplicate (or concurrent) delivery is recognised and dropped
|
||||||
|
// before it touches the projection, so the projection stays a faithful derived artefact.
|
||||||
|
if (!await log.TryRecordAsync(recorded, ct))
|
||||||
|
return;
|
||||||
|
|
||||||
|
await store.UpsertAsync(ToEntry(recorded), ct);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Rebuild the projection from the durable notification log (PRD §8.4).</summary>
|
/// <summary>Rebuild the projection from the durable notification log (PRD §8.4).</summary>
|
||||||
public Task RebuildAsync(CancellationToken ct = default)
|
public async Task RebuildAsync(CancellationToken ct = default)
|
||||||
// RED: not yet implemented.
|
{
|
||||||
=> Task.CompletedTask;
|
await store.ClearAsync(ct);
|
||||||
|
foreach (var recorded in await log.AllAsync(ct))
|
||||||
|
await store.UpsertAsync(ToEntry(recorded), ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The minimal projection row for an accepted notification. A zaak-create maps to
|
||||||
|
/// INGEDIEND; bsn/naam are deferred (ADR-0008).</summary>
|
||||||
|
private static RegisterEntry ToEntry(RecordedNotification recorded)
|
||||||
|
=> new(recorded.ZaakId, RegistrationStatus.Ingediend);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user