All checks were successful
## What & why First sub-slice of **S-11 · Withdrawal (Flow 3)** (#12). A zorgprofessional can withdraw a still-open registration ("trek aanvraag in"); this sub-slice delivers the **domain transition + endpoint**, mirroring how S-12a shipped the beoordeling decision model on its own (#82). - `RegistrationStatus.Ingetrokken` (terminal). - `Registration.Withdraw()` — allowed from INGEDIEND or IN_BEHANDELING, needs no zaak, idempotent, and rejected once the registration has been decided (INGESCHREVEN/AFGEWEZEN). - `WithdrawRegistration` application handler (load → withdraw → persist; repeated withdrawal is a no-op). - `POST /registrations/{id}/withdraw` on the domain API. Demoable: `POST /registrations/{id}/withdraw` → `GET /registrations/{id}` shows `INGETROKKEN`. Refs #12 (not closing — see below). ## Scope / follow-ups S-11 is bigger than one slice, so it is split (CLAUDE.md §13), like S-12 was: - **S-11a (this PR)** — domain withdrawal transition + endpoint. - **S-11b** — cancel the running Flowable process via a BPMN message event, so a withdrawn case leaves the behandelaar's werkbak. - **S-11c** — owner-scoped BFF self-service withdraw endpoint + "trek aanvraag in" button + e2e. Cancelling the Flowable process is deliberately deferred (documented in `WithdrawRegistration`), exactly as the beoordeling's rejection deferred its zaak propagation. #12 stays open until S-11c. ## Definition of Done - [x] Linked Gitea issue (#12). - [x] Failing test committed before the implementation. - [x] Implementation makes the test pass. - [x] Conventional Commits referencing the issue (`refs #12`). - [ ] CI green — all Gitea Actions jobs. - [x] `docker compose up` unaffected (no infra/contract change). - [x] Docs — none needed for this backend sub-slice; the user-visible demo note lands with S-11c. - [x] No ADR needed — mirrors existing aggregate/handler/endpoint patterns; no boundary change. ## Notes for reviewers - Verified locally: `Big.Tests` 89/89 pass; `Big.Api` builds clean. - The domain trusts its callers (§8.3); owner-scoping by the caller's bsn is enforced at the BFF in S-11c. Reviewed-on: #88
119 lines
6.0 KiB
C#
119 lines
6.0 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. Idempotent. The BFF reaches this behind a digid token, owner-scoped
|
|
// to the caller's bsn (S-11c); the domain trusts its callers (§8.3). Cancelling the running Flowable
|
|
// process is a later sub-slice (S-11b).
|
|
app.MapPost("/registrations/{id}/withdraw", async (string id, WithdrawRegistration withdraw, CancellationToken ct) =>
|
|
{
|
|
if (!Guid.TryParse(id, out var guid))
|
|
return Results.NotFound();
|
|
|
|
await withdraw.HandleAsync(new WithdrawRegistrationCommand(new RegistrationId(guid)), ct);
|
|
return Results.NoContent();
|
|
});
|
|
|
|
// 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 RegistrationResponse(string RegistrationId, string Status, string? ZaakUrl);
|
|
|
|
public partial class Program;
|