-
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.
refactor: use time provider in contracts
- Loading branch information
1 parent
4bb0257
commit 7088c76
Showing
3 changed files
with
18 additions
and
9 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
...tion/Fitnet.Contracts/Src/Fitnet.Contracts.Application/Sign/SignContractCommandHandler.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,27 +1,27 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Contracts.Application.Sign; | ||
|
||
using Common.Api.ErrorHandling; | ||
using Common.Core.SystemClock; | ||
using Core; | ||
using IntegrationEvents; | ||
using MassTransit; | ||
|
||
[UsedImplicitly] | ||
internal sealed class SignContractCommandHandler( | ||
IContractsRepository contractsRepository, | ||
ISystemClock systemClock, | ||
TimeProvider timeProvider, | ||
IPublishEndpoint publishEndpoint) : IRequestHandler<SignContractCommand> | ||
{ | ||
public async Task Handle(SignContractCommand command, CancellationToken cancellationToken) | ||
{ | ||
var contract = await contractsRepository.GetByIdAsync(command.Id, cancellationToken) ?? | ||
throw new ResourceNotFoundException(command.Id); | ||
contract.Sign(command.SignedAt, systemClock.Now); | ||
contract.Sign(command.SignedAt, timeProvider.GetUtcNow()); | ||
await contractsRepository.CommitAsync(cancellationToken); | ||
var @event = ContractSignedEvent.Create(contract.Id, | ||
contract.CustomerId, | ||
contract.SignedAt!.Value, | ||
contract.ExpiringAt!.Value); | ||
contract.ExpiringAt!.Value, | ||
timeProvider.GetUtcNow()); | ||
await publishEndpoint.Publish(@event, cancellationToken); | ||
} | ||
} |
17 changes: 14 additions & 3 deletions
17
...extraction/Fitnet.Contracts/Src/Fitnet.Contracts.IntegrationEvents/ContractSignedEvent.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,7 +1,18 @@ | ||
namespace EvolutionaryArchitecture.Fitnet.Contracts.IntegrationEvents; | ||
|
||
public sealed record ContractSignedEvent(Guid Id, Guid ContractId, Guid ContractCustomerId, DateTimeOffset SignedAt, DateTimeOffset ExpireAt, DateTimeOffset OccurredDateTime) | ||
public sealed record ContractSignedEvent( | ||
Guid Id, | ||
Guid ContractId, | ||
Guid ContractCustomerId, | ||
DateTimeOffset SignedAt, | ||
DateTimeOffset ExpireAt, | ||
DateTimeOffset OccurredDateTime) | ||
{ | ||
public static ContractSignedEvent Create(Guid contractId, Guid contractCustomerId, DateTimeOffset signedAt, DateTimeOffset expireAt) => | ||
new(Guid.NewGuid(), contractId, contractCustomerId, signedAt, expireAt, DateTimeOffset.UtcNow); | ||
public static ContractSignedEvent Create( | ||
Guid contractId, | ||
Guid contractCustomerId, | ||
DateTimeOffset signedAt, | ||
DateTimeOffset expireAt, | ||
DateTimeOffset occurredAt) => | ||
new(Guid.NewGuid(), contractId, contractCustomerId, signedAt, expireAt, occurredAt); | ||
} |
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