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

Allow to override events and expected version #397

Merged
merged 15 commits into from
Dec 27, 2024
Prev Previous commit
Next Next commit
Fix the functional service result
  • Loading branch information
alexeyzimarev committed Dec 23, 2024
commit c19b938867af79e54ae0d7fb6ed0d6403fe9ec4e
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<Result<TState>> Handle<TCommand>(TCommand command, Cancellatio
_ => throw new ArgumentOutOfRangeException(nameof(registeredHandler.ExpectedState), "Unknown expected state")
};

var result = await registeredHandler.Handler(loadedState.State, loadedState.Events, command, cancellationToken).NoContext();
var result = (await registeredHandler.Handler(loadedState.State, loadedState.Events, command, cancellationToken).NoContext()).ToArray();

var newEvents = result.Select(x => new ProposedEvent(x, new())).ToArray();
var newState = newEvents.Aggregate(loadedState.State, (current, evt) => current.When(evt));
Expand All @@ -97,7 +97,7 @@ public async Task<Result<TState>> Handle<TCommand>(TCommand command, Cancellatio
var proposed = new ProposedAppend(streamName, loadedState.StreamVersion, newEvents);
var final = registeredHandler.AmendAppend?.Invoke(proposed, command) ?? proposed;
var storeResult = await resolvedWriter.Store(final, Amend, cancellationToken).NoContext();
var changes = newEvents.Select(x => Change.FromEvent(x, _typeMap));
var changes = result.Select(x => Change.FromEvent(x, _typeMap));
Log.CommandHandled<TCommand>();

return Result<TState>.FromSuccess(newState, changes, storeResult.GlobalPosition);
Expand Down
Loading