From 39b2388a9d31eb5fc8ec5e1a4bd176083b2bd384 Mon Sep 17 00:00:00 2001 From: Niek Otten Date: Tue, 30 Jun 2026 17:00:05 +0200 Subject: [PATCH] feat(domain): implement SubmitRegistration and OpenZaakWorker (refs #6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SubmitRegistration creates the aggregate, persists it, starts the registratie process via the Workflow Client, records the instance id and upserts. OpenZaakWorker loads the correlated registration, opens a zaak via the ACL, attaches it and saves; an unknown registration throws (job redelivered), and an already-opened zaak short- circuits without opening a second one (ยง8.6). Co-Authored-By: Claude Opus 4.8 (1M context) --- services/domain/Big.Application/OpenZaakWorker.cs | 15 ++++++++++++--- .../domain/Big.Application/SubmitRegistration.cs | 14 +++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/services/domain/Big.Application/OpenZaakWorker.cs b/services/domain/Big.Application/OpenZaakWorker.cs index 6f01c36..be0688f 100644 --- a/services/domain/Big.Application/OpenZaakWorker.cs +++ b/services/domain/Big.Application/OpenZaakWorker.cs @@ -20,8 +20,17 @@ public sealed class OpenZaakWorker(IRegistrationStore store, IAclClient acl) { ArgumentNullException.ThrowIfNull(job); - // STUB (red): does not load, call the ACL, or attach. - await Task.CompletedTask; - return new Uri("about:blank"); + var registration = await store.GetAsync(job.RegistrationId, ct) + ?? throw new InvalidOperationException( + $"No registration {job.RegistrationId} for OpenZaakAanmaken job {job.JobId}."); + + // A redelivered job whose zaak was already opened completes without opening a second one. + if (registration.ZaakUrl is not null) + return registration.ZaakUrl; + + var zaakUrl = await acl.OpenZaakAsync(registration.Bsn, ct); + registration.AttachZaak(zaakUrl); + await store.SaveAsync(registration, ct); + return zaakUrl; } } diff --git a/services/domain/Big.Application/SubmitRegistration.cs b/services/domain/Big.Application/SubmitRegistration.cs index c4f3555..3e2f55f 100644 --- a/services/domain/Big.Application/SubmitRegistration.cs +++ b/services/domain/Big.Application/SubmitRegistration.cs @@ -18,8 +18,16 @@ public sealed class SubmitRegistration(IRegistrationStore store, IWorkflowClient { ArgumentNullException.ThrowIfNull(command); - // STUB (red): no persistence, no process start. - await Task.CompletedTask; - return RegistrationId.New(); + var registration = Registration.Submit(command.Bsn); + + // Persist before starting the process so the worker can correlate the OpenZaakAanmaken + // job back to an aggregate that already exists (ADR-0009). + await store.SaveAsync(registration, ct); + + var processInstanceId = await workflow.StartRegistrationProcessAsync(registration.Id, ct); + registration.RecordProcessStarted(processInstanceId); + await store.SaveAsync(registration, ct); + + return registration.Id; } }