-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51f082b
commit afe14bb
Showing
8 changed files
with
50 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 10 additions & 12 deletions
22
...ts.Application/AttachAnnexToBindingContract/AttachAnnexToBindingContractCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Contracts.Application.AttachAnnexToBindingContract; | ||
|
||
using Common.Api.ErrorHandling; | ||
|
||
[UsedImplicitly] | ||
internal sealed class AttachAnnexToBindingContractCommandHandler( | ||
IBindingContractsRepository bindingContractsRepository, | ||
TimeProvider timeProvider) : IRequestHandler<AttachAnnexToBindingContractCommand, Guid> | ||
TimeProvider timeProvider) : IRequestHandler<AttachAnnexToBindingContractCommand, ErrorOr<Guid>> | ||
{ | ||
public async Task<Guid> Handle(AttachAnnexToBindingContractCommand command, CancellationToken cancellationToken) | ||
{ | ||
var bindingContract = | ||
await bindingContractsRepository.GetByIdAsync(command.BindingContractId, cancellationToken) ?? | ||
throw new ResourceNotFoundException(command.BindingContractId); | ||
var annexId = bindingContract.AttachAnnex(command.ValidFrom, timeProvider.GetUtcNow()); | ||
await bindingContractsRepository.CommitAsync(cancellationToken); | ||
public async Task<ErrorOr<Guid>> Handle(AttachAnnexToBindingContractCommand command, | ||
CancellationToken cancellationToken) => | ||
await bindingContractsRepository.GetByIdAsync(command.BindingContractId, cancellationToken) | ||
.ThenAsync(bindingContract => bindingContract.AttachAnnex(command.ValidFrom, timeProvider.GetUtcNow()) | ||
.ThenAsync(async annexId => | ||
{ | ||
await bindingContractsRepository.CommitAsync(cancellationToken); | ||
|
||
return annexId.Value; | ||
} | ||
return annexId.Value; | ||
})); | ||
} |
5 changes: 2 additions & 3 deletions
5
...al-domain-driven-design/Fitnet.Contracts/Src/Fitnet.Contracts.Application/GlobalUsings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
global using System.Threading.Tasks; | ||
global using ErrorOr; | ||
global using ErrorOr; | ||
global using JetBrains.Annotations; | ||
global using MediatR; | ||
global using MediatR; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 9 additions & 11 deletions
20
....Contracts.Application/TerminateBindingContract/TerminateBindingContractCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Contracts.Application.TerminateBindingContract; | ||
|
||
using Common.Api.ErrorHandling; | ||
using ErrorOr; | ||
|
||
[UsedImplicitly] | ||
internal sealed class TerminateBindingContractCommandHandler( | ||
IBindingContractsRepository bindingContractsRepository, | ||
TimeProvider timeProvider) : IRequestHandler<TerminateBindingContractCommand, ErrorOr<Unit>> | ||
{ | ||
public async Task<ErrorOr<Unit>> Handle(TerminateBindingContractCommand command, CancellationToken cancellationToken) | ||
{ | ||
var contract = await bindingContractsRepository.GetByIdAsync(command.BindingContractId, cancellationToken) ?? | ||
throw new ResourceNotFoundException(command.BindingContractId); | ||
var terminatedAt = timeProvider.GetUtcNow(); | ||
contract.Terminate(terminatedAt); | ||
await bindingContractsRepository.CommitAsync(cancellationToken); | ||
|
||
return Unit.Value; | ||
} | ||
public async Task<ErrorOr<Unit>> Handle(TerminateBindingContractCommand command, | ||
CancellationToken cancellationToken) => | ||
await bindingContractsRepository.GetByIdAsync(command.BindingContractId, cancellationToken) | ||
.ThenAsync(bindingContract => bindingContract.Terminate(timeProvider.GetUtcNow()) | ||
.ThenAsync(async _ => | ||
{ | ||
await bindingContractsRepository.CommitAsync(cancellationToken); | ||
return Unit.Value; | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...domain-driven-design/Fitnet.Contracts/Src/Fitnet.Contracts.Infrastructure/GlobalUsings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
global using System; | ||
global using System.Diagnostics.CodeAnalysis; | ||
global using System.Diagnostics.CodeAnalysis; |
3 changes: 1 addition & 2 deletions
3
...main-driven-design/Fitnet.Contracts/Src/Fitnet.Contracts.IntegrationTests/GlobalUsings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
global using System.Net; | ||
global using System.Net.Http.Json; | ||
global using Xunit; | ||
global using Bogus; | ||
global using FluentAssertions; | ||
global using FluentAssertions; |