## What & why Third sub-slice of **S-11 · Withdrawal (Flow 3)** (#12) — the **owner-scoped BFF withdraw endpoint** (backend). S-11a/b made a withdrawal transition the aggregate and cancel the workflow; this adds the citizen-facing entry point through the BFF, gated to the registration's owner. - **Domain**: `WithdrawRegistrationCommand` carries the caller's `bsn`; the handler returns a `WithdrawOutcome` and refuses a bsn that doesn't own the registration. Unknown and not-owned are **both 404** (indistinguishable — ownership isn't revealed). `POST /registrations/{id}/withdraw` takes `{bsn}` and maps the outcome (204/404). - **BFF**: `POST /self-service/registrations/{id}/withdraw` (DigiD-authenticated) forwards the token's `bsn` to the domain and relays 204/404. The BFF authenticates; the domain owner-scopes (an aggregate invariant, not the domain doing auth). - OpenAPI spec + Angular client regenerated for the new endpoint. - `run-domain-check.sh` withdrawal step now sends the owner `bsn` (verify-stack). Refs #12 — the self-service "trek aanvraag in" button + e2e (S-11c-2) closes it. ## Definition of Done - [x] Linked Gitea issue (#12). - [x] Failing tests committed before the implementation. - [x] Implementation makes the tests pass. - [x] Conventional Commits referencing the issue (`refs #12`). - [ ] CI green — all Gitea Actions jobs. - [x] `docker compose up` unaffected. - [x] No ADR needed (owner-scoping is an aggregate invariant; no boundary change). - [x] Docs — the user-visible demo note lands with S-11c-2. ## Notes for reviewers - **Full local gate run before pushing this time** (lessons from #89): `dotnet format --verify-no-changes` clean; `make unit` green — Acl 27, EventSubscriber 19, BFF 30, Acceptance 9, Big 95; `api-client` lint+test green. - Owner mismatch returns 404 (not 403) so the portal can't be used to probe which references exist. Reviewed-on: #90
124 lines
6.3 KiB
C#
124 lines
6.3 KiB
C#
using Big.Application;
|
|
using Big.Domain;
|
|
using Big.Infrastructure;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Options bound from configuration (compose sets Flowable__* and Acl__* env vars).
|
|
builder.Services.AddSingleton(sp => sp.GetRequiredService<IConfiguration>()
|
|
.GetSection("Flowable").Get<FlowableOptions>()
|
|
?? throw new InvalidOperationException("Missing configuration section 'Flowable'"));
|
|
builder.Services.AddSingleton(sp => sp.GetRequiredService<IConfiguration>()
|
|
.GetSection("Acl").Get<AclOptions>()
|
|
?? throw new InvalidOperationException("Missing configuration section 'Acl'"));
|
|
|
|
// The in-memory registration store is shared between the submit endpoint and the worker (ADR-0009).
|
|
builder.Services.AddSingleton<IRegistrationStore, InMemoryRegistrationStore>();
|
|
|
|
// The Workflow Client is one type behind two ports (start side + worker side); both resolve to the
|
|
// same HttpClient-backed implementation — the only code that talks to Flowable (§8.2).
|
|
builder.Services.AddHttpClient<FlowableWorkflowClient>();
|
|
builder.Services.AddTransient<IWorkflowClient>(sp => sp.GetRequiredService<FlowableWorkflowClient>());
|
|
builder.Services.AddTransient<IExternalWorkerClient>(sp => sp.GetRequiredService<FlowableWorkflowClient>());
|
|
builder.Services.AddTransient<IUserTaskClient>(sp => sp.GetRequiredService<FlowableWorkflowClient>());
|
|
builder.Services.AddHttpClient<IAclClient, AclHttpClient>();
|
|
|
|
builder.Services.AddScoped<SubmitRegistration>();
|
|
builder.Services.AddScoped<ApproveRegistration>();
|
|
builder.Services.AddScoped<BeoordeelRegistratie>();
|
|
builder.Services.AddScoped<WithdrawRegistration>();
|
|
builder.Services.AddScoped<Werkbak>();
|
|
builder.Services.AddScoped<OpenZaakWorker>();
|
|
builder.Services.AddScoped<OpenZaakJobProcessor>();
|
|
|
|
// The hosted external-task job worker polls Flowable and drives OpenZaakAanmaken to completion.
|
|
builder.Services.AddHostedService<OpenZaakJobPump>();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.MapGet("/health", () => "Healthy");
|
|
|
|
// Submit a registration. The aggregate is created (INGEDIEND) and the registratie process started;
|
|
// the zaak is opened later, off the request path, by the worker — so this returns 202 Accepted with
|
|
// a location to read the registration's progress (ADR-0009, eventual consistency).
|
|
app.MapPost("/registrations", async (SubmitRegistrationRequest body, SubmitRegistration submit, CancellationToken ct) =>
|
|
{
|
|
var id = await submit.HandleAsync(new SubmitRegistrationCommand(body.Bsn), ct);
|
|
return Results.Accepted($"/registrations/{id}", new RegistrationResponse(id.ToString(), RegistrationStatus.Ingediend.ToString(), null));
|
|
});
|
|
|
|
// Temporary admin endpoint (S-09b): approve a registration — the behandelaar's decision, until the
|
|
// behandel-portal exists (S-12). The zaak's final status is set via the ACL, which flows back over
|
|
// NRC to the projection, making the entry publicly visible as INGESCHREVEN. Idempotent.
|
|
app.MapPost("/registrations/{id}/approve", async (string id, ApproveRegistration approve, CancellationToken ct) =>
|
|
{
|
|
if (!Guid.TryParse(id, out var guid))
|
|
return Results.NotFound();
|
|
|
|
await approve.HandleAsync(new ApproveRegistrationCommand(new RegistrationId(guid)), ct);
|
|
return Results.NoContent();
|
|
});
|
|
|
|
// The behandelaar's beoordeling (S-12): decide a registration goedkeuren (→ INGESCHREVEN, sets the
|
|
// zaak's final status via the ACL) or afwijzen (→ AFGEWEZEN). Idempotent. This is the domain contract
|
|
// the behandel-portal's decision reaches through the BFF; it supersedes the temporary /approve above,
|
|
// which is retired once the portal lands.
|
|
app.MapPost("/registrations/{id}/decide", async (string id, DecideRequest body, BeoordeelRegistratie beoordeel, CancellationToken ct) =>
|
|
{
|
|
if (!Guid.TryParse(id, out var guid))
|
|
return Results.NotFound();
|
|
|
|
if (!Enum.TryParse<BeoordelingsBesluit>(body.Besluit, ignoreCase: true, out var besluit))
|
|
return Results.BadRequest(new { error = $"Unknown besluit '{body.Besluit}'. Expected 'goedkeuren' or 'afwijzen'." });
|
|
|
|
await beoordeel.HandleAsync(new BeoordeelRegistratieCommand(new RegistrationId(guid), besluit), ct);
|
|
return Results.NoContent();
|
|
});
|
|
|
|
// Withdraw a registration (S-11): the zorgprofessional pulls their own still-open submission back,
|
|
// advancing it to INGETROKKEN and cancelling its workflow. Owner-scoped by the caller's bsn (the BFF
|
|
// forwards it from the DigiD token, S-11c); a registration that is unknown or not the caller's is
|
|
// 404 (indistinguishable, so ownership isn't leaked). Idempotent.
|
|
app.MapPost("/registrations/{id}/withdraw", async (string id, WithdrawRequest body, WithdrawRegistration withdraw, CancellationToken ct) =>
|
|
{
|
|
if (!Guid.TryParse(id, out var guid))
|
|
return Results.NotFound();
|
|
|
|
if (string.IsNullOrWhiteSpace(body?.Bsn))
|
|
return Results.BadRequest(new { error = "A bsn is required to withdraw a registration." });
|
|
|
|
var outcome = await withdraw.HandleAsync(new WithdrawRegistrationCommand(new RegistrationId(guid), body.Bsn), ct);
|
|
return outcome == WithdrawOutcome.Withdrawn ? Results.NoContent() : Results.NotFound();
|
|
});
|
|
|
|
// The behandelaar's werkbak (S-12): the registrations awaiting beoordeling, read from the open
|
|
// Beoordelen user tasks (§8.2) and enriched with bsn + status. The BFF proxies this behind
|
|
// medewerker-realm + behandelaar-role authorization; the domain trusts its callers (§8.3).
|
|
app.MapGet("/behandel/werkbak", async (Werkbak werkbak, CancellationToken ct) =>
|
|
Results.Ok(await werkbak.GetAsync(ct)));
|
|
|
|
// Read a registration. Its zaak URL appears once the worker has opened the zaak (eventually).
|
|
app.MapGet("/registrations/{id}", async (string id, IRegistrationStore store, CancellationToken ct) =>
|
|
{
|
|
if (!Guid.TryParse(id, out var guid))
|
|
return Results.NotFound();
|
|
|
|
var registration = await store.GetAsync(new RegistrationId(guid), ct);
|
|
return registration is null
|
|
? Results.NotFound()
|
|
: Results.Ok(new RegistrationResponse(
|
|
registration.Id.ToString(), registration.Status.ToString(), registration.ZaakUrl?.ToString()));
|
|
});
|
|
|
|
await app.RunAsync();
|
|
|
|
public sealed record SubmitRegistrationRequest(string Bsn);
|
|
|
|
public sealed record DecideRequest(string Besluit);
|
|
|
|
public sealed record WithdrawRequest(string Bsn);
|
|
|
|
public sealed record RegistrationResponse(string RegistrationId, string Status, string? ZaakUrl);
|
|
|
|
public partial class Program;
|