-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPullRequestService.cs
36 lines (27 loc) · 1.13 KB
/
PullRequestService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Arjen Post. See LICENSE in the project root for license information.
using Giddup.ApplicationCore.Domain.PullRequests;
namespace Giddup.ApplicationCore.Application.PullRequests;
public class PullRequestService : IPullRequestService
{
private readonly IPullRequestStateProvider _stateProvider;
private readonly IPullRequestEventProcessor _eventProcessor;
public PullRequestService(IPullRequestStateProvider stateProvider, IPullRequestEventProcessor eventProcessor)
{
_stateProvider = stateProvider;
_eventProcessor = eventProcessor;
}
public async Task<IPullRequestError?> ProcessCommand(Guid pullRequestId, IPullRequestCommand command)
{
var (state, version) = await _stateProvider.Provide(pullRequestId);
var result = await PullRequestCommandProcessor.Process(state, command);
if (!result.TryGetEvents(out var events, out var error))
{
return error;
}
if (!await _eventProcessor.Process(pullRequestId, version, events))
{
return new OptimisticConcurrencyCheckError();
}
return null;
}
}