Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: or-2006 add extra duplicate check closer to persisting event #577

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<Result> Handle(CommandEnvelope<RegistreerVerenigingUitKboComma

if (vereniging.IsFailure()) throw new GeenGeldigeVerenigingInKbo();

return Result.Success(await RegistreerVereniging(vereniging, message.Metadata, cancellationToken));
return await RegistreerVereniging(vereniging, message.Metadata, cancellationToken);
}

private async Task<Result> CheckForDuplicate(KboNummer kboNummer)
Expand All @@ -45,16 +45,20 @@ private async Task<Result> CheckForDuplicate(KboNummer kboNummer)
return duplicateKbo is not null ? DuplicateKboFound.WithVcode(duplicateKbo.VCode!) : Result.Success();
}

private async Task<CommandResult> RegistreerVereniging(VerenigingVolgensKbo verenigingVolgensKbo, CommandMetadata messageMetadata, CancellationToken cancellationToken)
private async Task<Result> RegistreerVereniging(VerenigingVolgensKbo verenigingVolgensKbo, CommandMetadata messageMetadata, CancellationToken cancellationToken)
{
var vCode = await _vCodeService.GetNext();

var vereniging = VerenigingMetRechtspersoonlijkheid.Registreer(
vCode,
verenigingVolgensKbo);

var duplicateResult = await CheckForDuplicate(verenigingVolgensKbo.KboNummer);

if (duplicateResult.IsFailure()) return duplicateResult;

var result = await _verenigingsRepository.Save(vereniging, messageMetadata, cancellationToken);

return CommandResult.Create(vCode, result);
return Result.Success(CommandResult.Create(vCode, result));
}
}
Loading