Ports, schema and failing tests for the subscriber half of S-19b-2, ahead of the implementation. The subscriber now listens on the `objecten` kanaal instead of `zaken`. An Objecten notification carries no record data — only the object URL — so the record is read back through the ACL (§8.1), and the zaak-shaped surface goes away: IsZaakCreated / IsZaakStatusSet / ZaakUrl / ZaakId and ToEntry's `Resource == "status"` mapping are replaced by IsRegisterRecordWritten + ObjectUrl. The notification log now holds the projected row itself (register id, status, reference), so a rebuild is a replay with no mapping rules and no upstream reads. The migration drops the old columns rather than renaming them — EF scaffolded renames that would have carried ZGW values into columns meaning something else — and empties both tables, since a pre-slice row is neither reprojectable nor re-derivable from the new source. Red: HandleAsync recognises a register write but does not yet read or project it, so the seven projection assertions fail on an empty store.
41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using EventSubscriber.Application;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Projection.ReadModel;
|
|
|
|
/// <summary>EF Core implementation of the notification log. Idempotency is enforced atomically
|
|
/// by the primary key on <c>key</c>: a duplicate insert raises a unique violation, which is
|
|
/// caught and reported as "already recorded" rather than failing the request.</summary>
|
|
public sealed class EfNotificationLog(ProjectionDbContext db) : INotificationLog
|
|
{
|
|
public async Task<bool> TryRecordAsync(RecordedNotification notification, CancellationToken ct = default)
|
|
{
|
|
db.ProcessedNotifications.Add(new ProcessedNotificationRow
|
|
{
|
|
Key = notification.Key,
|
|
RegisterId = notification.RegisterId,
|
|
Status = notification.Status,
|
|
Reference = notification.Reference,
|
|
ReceivedAt = DateTimeOffset.UtcNow,
|
|
});
|
|
|
|
try
|
|
{
|
|
await db.SaveChangesAsync(ct);
|
|
return true;
|
|
}
|
|
catch (DbUpdateException)
|
|
{
|
|
// Already recorded by an earlier (or concurrent) delivery — drop this duplicate.
|
|
db.ChangeTracker.Clear();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public async Task<IReadOnlyList<RecordedNotification>> AllAsync(CancellationToken ct = default)
|
|
=> await db.ProcessedNotifications
|
|
.OrderBy(r => r.ReceivedAt)
|
|
.Select(r => new RecordedNotification(r.Key, r.RegisterId, r.Status, r.Reference))
|
|
.ToListAsync(ct);
|
|
}
|