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:
43
services/projection-api/ProjectionApi.Api/Program.cs
Normal file
43
services/projection-api/ProjectionApi.Api/Program.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Projection.ReadModel;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("Projection")
|
||||
?? throw new InvalidOperationException("Missing connection string 'ConnectionStrings:Projection'");
|
||||
|
||||
builder.Services.AddProjectionReadModel(connectionString);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Ensure the schema exists before serving reads. EF serialises concurrent migrators via the
|
||||
// migrations-history lock, so it is safe that the Event Subscriber migrates too.
|
||||
await app.Services.MigrateProjectionAsync();
|
||||
|
||||
app.MapGet("/health", () => "Healthy");
|
||||
|
||||
// The read side of the projection. Public-safe field filtering is tightened in S-09; for now
|
||||
// the minimal projection only carries id + status (bsn/naam deferred — ADR-0008).
|
||||
app.MapGet("/register", async (ProjectionDbContext db, CancellationToken ct) =>
|
||||
{
|
||||
var rows = await db.RegisterEntries
|
||||
.OrderBy(r => r.Id)
|
||||
.Select(r => new RegisterEntryDto(r.Id, r.Status, r.Bsn, r.NaamPlaceholder))
|
||||
.ToListAsync(ct);
|
||||
return Results.Ok(rows);
|
||||
});
|
||||
|
||||
app.MapGet("/register/{id}", async (string id, ProjectionDbContext db, CancellationToken ct) =>
|
||||
{
|
||||
var row = await db.RegisterEntries
|
||||
.Where(r => r.Id == id)
|
||||
.Select(r => new RegisterEntryDto(r.Id, r.Status, r.Bsn, r.NaamPlaceholder))
|
||||
.SingleOrDefaultAsync(ct);
|
||||
return row is null ? Results.NotFound() : Results.Ok(row);
|
||||
});
|
||||
|
||||
await app.RunAsync();
|
||||
|
||||
public sealed record RegisterEntryDto(string Id, string Status, string? Bsn, string? NaamPlaceholder);
|
||||
|
||||
public partial class Program;
|
||||
Reference in New Issue
Block a user