feat(projection): persist the read projection and expose webhook + read APIs (refs #7)
Add the projection persistence and the two services around it:
- Projection.ReadModel: a shared EF Core (Npgsql) read model owning the projection
schema — register_projection + the subscriber's processed_notifications log — plus
EfProjectionStore / EfNotificationLog (atomic record-or-skip on the PK for idempotency)
and the initial migration. One rebuildable store, written by the subscriber and read
by projection-api (ADR-0008).
- EventSubscriber.Api: POST /notifications NRC callback (enforces the abonnement bearer,
401 without it per ADR-0007), POST /admin/rebuild, /health. Migrates on start.
- ProjectionApi.Api: GET /register, GET /register/{id}, /health — the read side.
dotnet-ef pinned as a local tool for migrations; NuGetAuditMode=direct so EF's
design-time-only tooling transitive doesn't flag the shipped build.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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,
|
||||
Bsn = entry.Bsn,
|
||||
NaamPlaceholder = entry.NaamPlaceholder,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Status = entry.Status;
|
||||
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, r.Bsn, r.NaamPlaceholder))
|
||||
.ToListAsync(ct);
|
||||
}
|
||||
Reference in New Issue
Block a user