## What & why After submitting, the self-service portal held the registration only in in-memory signals, so a **page refresh stranded an in-flight registration** — the reference and its "Documenten aanleveren" / "Trek aanvraag in" actions were lost, with no way back (the reference wasn't in the URL and there was no read endpoint). This is the gap a citizen hit in testing. Now the portal **resumes on load**: - **Domain:** `IRegistrationStore.FindOpenByBsnAsync` (the citizen's non-terminal INGEDIEND/IN_BEHANDELING registration) + `GET /registrations/current?bsn=`. - **BFF:** owner-scoped `GET /self-service/registrations` (bsn from the DigiD token) → the current registration, or **204** when none. Regenerated `services/bff/openapi.json`. - **Frontend:** `registration-page` calls it on init and restores the submitted view (reference + actions); 204 shows the submit form as before. api-client regenerated (orval). Closes #111 ## Definition of Done - [x] Linked issue (#111). - [x] TDD — store `FindOpenByBsnAsync` tests, BFF endpoint tests, an Angular component test (resume-on-load), a Playwright e2e (submit → reload → restored). - [x] Conventional Commits referencing #111. - [ ] CI green — validated locally (below); runner CI running. - [x] `docker compose up` reaches green health — fresh stack + full e2e (3 specs) green. - [x] Docs — `docs/synthetic-data.md` (new e2e users). - [ ] ADR — N/A (follows existing BFF/domain patterns; no boundary change). - [ ] Demo note — the flow is unchanged for the demo; no new demo-script section (happy to add one if wanted). ## Verified locally - Unit: Big 141 (+7 store tests), Bff 36 (+3 endpoint tests), all suites green. - Frontend: 12 self-service component tests (incl. resume-on-load); lint + build green. - **e2e (fresh CI stack): all 3 specs pass** — `registration`, `resume`, `withdrawal` (29.5s, single worker). - Mutation: domain **91.04%**, bff **100%** (break 90%). `make lint` clean. ## Notes for reviewers - **Shared-stack isolation:** resume-on-load restores any open registration for the logged-in bsn, so the self-service e2e specs can no longer share `jan-burger` (the verify-* API checks submit as `jan-burger`/`123456782` before the e2e). Each spec now has its own DigiD citizen (`emma`/`sanne`/`lars`-burger); `jan-burger` stays the documented citizen for the verify checks. This is the fix for the two intermittent e2e failures seen during development. - **Scope:** resumes the current **in-flight** registration only (terminal ones aren't resumed), per the issue's out-of-scope note. Reviewed-on: #119
124 lines
6.7 KiB
C#
124 lines
6.7 KiB
C#
using System.Net.Http.Json;
|
|
|
|
namespace Bff.Api;
|
|
|
|
/// <summary>What the self-service submit returns to the portal (the domain's registration id + status).</summary>
|
|
public sealed record SubmitAccepted(string RegistrationId, string Status);
|
|
|
|
/// <summary>The caller's current open registration, for resuming the self-service portal after a
|
|
/// refresh (S-26): the reference (registration id) + its status.</summary>
|
|
public sealed record CurrentRegistration(string RegistrationId, string Status);
|
|
|
|
/// <summary>A projection row as the projection-api serves it. <c>Bsn</c>/<c>NaamPlaceholder</c> are
|
|
/// read but never surfaced by the openbaar endpoint (public-safe filtering, ADR-0010/S-09).
|
|
/// <c>Reference</c> is the public-safe citizen reference (the zaak identificatie, #78).</summary>
|
|
public sealed record ProjectionEntry(string Id, string Status, string? Reference, string? Bsn, string? NaamPlaceholder);
|
|
|
|
/// <summary>A public-safe openbaar register row — only non-sensitive fields leave the BFF.</summary>
|
|
public sealed record OpenbaarEntry(string Id, string Status, string? Reference);
|
|
|
|
/// <summary>A behandelaar's werkbak row: a registration awaiting beoordeling, with the bsn + status a
|
|
/// behandelaar sees (staff view — reached only behind medewerker/behandelaar authorization, S-12c).</summary>
|
|
public sealed record WerkbakItem(string RegistrationId, string Bsn, string Status);
|
|
|
|
/// <summary>Port to the Domain Service (§8.3: the BFF is the portals' only backend; it fans out).</summary>
|
|
public interface IDomainClient
|
|
{
|
|
Task<SubmitAccepted> SubmitRegistrationAsync(string bsn, CancellationToken ct = default);
|
|
|
|
/// <summary>The caller's current open registration (resume after refresh, S-26), or <c>null</c>
|
|
/// when they have none in flight. Owner-scoped by <paramref name="bsn"/>.</summary>
|
|
Task<CurrentRegistration?> GetCurrentRegistrationAsync(string bsn, CancellationToken ct = default);
|
|
|
|
/// <summary>Withdraw the caller's own registration ("trek aanvraag in"). Owner-scoped by
|
|
/// <paramref name="bsn"/>. Returns <c>false</c> when the domain reports the registration is
|
|
/// unknown or not the caller's (404), so the BFF can relay a 404 rather than a 500.</summary>
|
|
Task<bool> WithdrawRegistrationAsync(string registrationId, string bsn, CancellationToken ct = default);
|
|
|
|
/// <summary>Provide (upload) the diploma the caller's own registration is waiting for ("documenten
|
|
/// aanleveren"). The file is carried base64-encoded. Owner-scoped by <paramref name="bsn"/>. Returns
|
|
/// <c>false</c> when the domain reports the registration is unknown or not the caller's (404).</summary>
|
|
Task<bool> ProvideDocumentsAsync(
|
|
string registrationId, string bsn, string contentBase64, string? fileName, string? contentType, CancellationToken ct = default);
|
|
|
|
/// <summary>The behandelaar's werkbak — registrations awaiting beoordeling.</summary>
|
|
Task<IReadOnlyList<WerkbakItem>> GetWerkbakAsync(CancellationToken ct = default);
|
|
|
|
/// <summary>Apply a behandelaar's decision (<c>goedkeuren</c>/<c>afwijzen</c>) to a registration.</summary>
|
|
Task DecideAsync(string registrationId, string besluit, CancellationToken ct = default);
|
|
}
|
|
|
|
/// <summary>Port to the read projection.</summary>
|
|
public interface IProjectionClient
|
|
{
|
|
Task<IReadOnlyList<ProjectionEntry>> GetRegisterAsync(CancellationToken ct = default);
|
|
}
|
|
|
|
/// <summary>Calls the Domain Service's <c>POST /registrations</c>.</summary>
|
|
public sealed class DomainClient(HttpClient http) : IDomainClient
|
|
{
|
|
public async Task<SubmitAccepted> SubmitRegistrationAsync(string bsn, CancellationToken ct = default)
|
|
{
|
|
using var response = await http.PostAsJsonAsync("registrations", new { bsn }, ct);
|
|
response.EnsureSuccessStatusCode();
|
|
var dto = await response.Content.ReadFromJsonAsync<DomainResponse>(ct)
|
|
?? throw new InvalidOperationException("The Domain Service returned an empty registration response.");
|
|
return new SubmitAccepted(dto.RegistrationId, dto.Status);
|
|
}
|
|
|
|
public async Task<CurrentRegistration?> GetCurrentRegistrationAsync(string bsn, CancellationToken ct = default)
|
|
{
|
|
using var response = await http.GetAsync($"registrations/current?bsn={Uri.EscapeDataString(bsn)}", ct);
|
|
// The domain 404s when the citizen has no open registration — that's "none", not an error.
|
|
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
|
return null;
|
|
response.EnsureSuccessStatusCode();
|
|
var dto = await response.Content.ReadFromJsonAsync<DomainResponse>(ct)
|
|
?? throw new InvalidOperationException("The Domain Service returned an empty registration response.");
|
|
return new CurrentRegistration(dto.RegistrationId, dto.Status);
|
|
}
|
|
|
|
public async Task<bool> WithdrawRegistrationAsync(string registrationId, string bsn, CancellationToken ct = default)
|
|
{
|
|
using var response = await http.PostAsJsonAsync(
|
|
$"registrations/{registrationId}/withdraw", new { bsn }, ct);
|
|
// The domain 404s an unknown or not-owned registration; relay that rather than fail hard.
|
|
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
|
return false;
|
|
response.EnsureSuccessStatusCode();
|
|
return true;
|
|
}
|
|
|
|
public async Task<bool> ProvideDocumentsAsync(
|
|
string registrationId, string bsn, string contentBase64, string? fileName, string? contentType, CancellationToken ct = default)
|
|
{
|
|
using var response = await http.PostAsJsonAsync(
|
|
$"registrations/{registrationId}/documents",
|
|
new { bsn, contentBase64, fileName, contentType }, ct);
|
|
// The domain 404s an unknown or not-owned registration; relay that rather than fail hard.
|
|
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
|
return false;
|
|
response.EnsureSuccessStatusCode();
|
|
return true;
|
|
}
|
|
|
|
public async Task<IReadOnlyList<WerkbakItem>> GetWerkbakAsync(CancellationToken ct = default)
|
|
=> await http.GetFromJsonAsync<List<WerkbakItem>>("behandel/werkbak", ct) ?? [];
|
|
|
|
public async Task DecideAsync(string registrationId, string besluit, CancellationToken ct = default)
|
|
{
|
|
using var response = await http.PostAsJsonAsync(
|
|
$"registrations/{registrationId}/decide", new { besluit }, ct);
|
|
response.EnsureSuccessStatusCode();
|
|
}
|
|
|
|
private sealed record DomainResponse(string RegistrationId, string Status, string? ZaakUrl);
|
|
}
|
|
|
|
/// <summary>Calls the projection-api's <c>GET /register</c>.</summary>
|
|
public sealed class ProjectionClient(HttpClient http) : IProjectionClient
|
|
{
|
|
public async Task<IReadOnlyList<ProjectionEntry>> GetRegisterAsync(CancellationToken ct = default)
|
|
=> await http.GetFromJsonAsync<List<ProjectionEntry>>("register", ct) ?? [];
|
|
}
|