Skip to content

Commit

Permalink
refactor: use time provider in contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
meaboutsoftware committed Apr 2, 2024
1 parent 4bb0257 commit 7088c76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
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);
}
}
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);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EvolutionaryArchitecture.Fitnet.Common.Api.ErrorHandling;
using EvolutionaryArchitecture.Fitnet.Common.Core.SystemClock;
using EvolutionaryArchitecture.Fitnet.Contracts.Api;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -8,7 +7,6 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddSystemClock();
builder.Services.AddFeatureManagement();

builder.Services.AddContractsApi(builder.Configuration);
Expand Down

0 comments on commit 7088c76

Please sign in to comment.