Skip to content

Commit

Permalink
feat: or-2006 simple solution for or-2006
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenGreenstack committed Dec 13, 2023
1 parent c644cfc commit e6ff56e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/AssociationRegistry/EventStore/EventStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ public EventStore(IDocumentStore documentStore)
_documentStore = documentStore;
}

public async Task<StreamActionResult> Save(string aggregateId, CommandMetadata metadata, CancellationToken cancellationToken = default, params IEvent[] events)
public async Task<StreamActionResult> Save(
string aggregateId,
CommandMetadata metadata,
CancellationToken cancellationToken = default,
params IEvent[] events)
{
await using var session = _documentStore.OpenSession();

Check warning on line 29 in src/AssociationRegistry/EventStore/EventStore.cs

View workflow job for this annotation

GitHub Actions / analyze-code

'IDocumentStore.OpenSession(DocumentTracking, IsolationLevel)' is obsolete: 'Opening a session without explicitly providing desired type may be dropped in next Marten version.

Check warning on line 29 in src/AssociationRegistry/EventStore/EventStore.cs

View workflow job for this annotation

GitHub Actions / Run Tests (test/AssociationRegistry.Test)

'IDocumentStore.OpenSession(DocumentTracking, IsolationLevel)' is obsolete: 'Opening a session without explicitly providing desired type may be dropped in next Marten version.

Check warning on line 29 in src/AssociationRegistry/EventStore/EventStore.cs

View workflow job for this annotation

GitHub Actions / Run Tests (test/AssociationRegistry.Test.Acm.Api)

'IDocumentStore.OpenSession(DocumentTracking, IsolationLevel)' is obsolete: 'Opening a session without explicitly providing desired type may be dropped in next Marten version.

Check warning on line 29 in src/AssociationRegistry/EventStore/EventStore.cs

View workflow job for this annotation

GitHub Actions / Run Tests (test/AssociationRegistry.Test.Public.Api)

'IDocumentStore.OpenSession(DocumentTracking, IsolationLevel)' is obsolete: 'Opening a session without explicitly providing desired type may be dropped in next Marten version.

Check warning on line 29 in src/AssociationRegistry/EventStore/EventStore.cs

View workflow job for this annotation

GitHub Actions / Run Tests (test/AssociationRegistry.Test.Admin.Api)

'IDocumentStore.OpenSession(DocumentTracking, IsolationLevel)' is obsolete: 'Opening a session without explicitly providing desired type may be dropped in next Marten version.

try
{
SetHeaders(metadata, session);

TryLockForKboNumber(aggregateId, session, events.FirstOrDefault());

var streamAction = AppendEvents(session, aggregateId, events, metadata.ExpectedVersion);

await session.SaveChangesAsync(cancellationToken);
Expand All @@ -40,6 +46,12 @@ public async Task<StreamActionResult> Save(string aggregateId, CommandMetadata m
}
}

private static void TryLockForKboNumber(string vCode, IDocumentSession session, IEvent? registreerEvent)
{
if (registreerEvent is VerenigingMetRechtspersoonlijkheidWerdGeregistreerd evnt)
session.Events.StartStream<KboNummer>(evnt.KboNummer, new { VCode = vCode });
}

private static StreamAction AppendEvents(IDocumentSession session, string aggregateId, IReadOnlyCollection<IEvent> events, long? expectedVersion)
{
if (expectedVersion is not null)
Expand Down

0 comments on commit e6ff56e

Please sign in to comment.