From e6ff56ec11506581cf212719f090958b1e71894a Mon Sep 17 00:00:00 2001 From: Quinten Van Assche Date: Wed, 13 Dec 2023 14:18:45 +0100 Subject: [PATCH] feat: or-2006 simple solution for or-2006 --- src/AssociationRegistry/EventStore/EventStore.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/AssociationRegistry/EventStore/EventStore.cs b/src/AssociationRegistry/EventStore/EventStore.cs index ad26ebc05..25f49bf00 100644 --- a/src/AssociationRegistry/EventStore/EventStore.cs +++ b/src/AssociationRegistry/EventStore/EventStore.cs @@ -20,7 +20,11 @@ public EventStore(IDocumentStore documentStore) _documentStore = documentStore; } - public async Task Save(string aggregateId, CommandMetadata metadata, CancellationToken cancellationToken = default, params IEvent[] events) + public async Task Save( + string aggregateId, + CommandMetadata metadata, + CancellationToken cancellationToken = default, + params IEvent[] events) { await using var session = _documentStore.OpenSession(); @@ -28,6 +32,8 @@ public async Task Save(string aggregateId, CommandMetadata m { SetHeaders(metadata, session); + TryLockForKboNumber(aggregateId, session, events.FirstOrDefault()); + var streamAction = AppendEvents(session, aggregateId, events, metadata.ExpectedVersion); await session.SaveChangesAsync(cancellationToken); @@ -40,6 +46,12 @@ public async Task Save(string aggregateId, CommandMetadata m } } + private static void TryLockForKboNumber(string vCode, IDocumentSession session, IEvent? registreerEvent) + { + if (registreerEvent is VerenigingMetRechtspersoonlijkheidWerdGeregistreerd evnt) + session.Events.StartStream(evnt.KboNummer, new { VCode = vCode }); + } + private static StreamAction AppendEvents(IDocumentSession session, string aggregateId, IReadOnlyCollection events, long? expectedVersion) { if (expectedVersion is not null)