Skip to content

Commit

Permalink
fix: operating on contract id instead of binding contract id
Browse files Browse the repository at this point in the history
  • Loading branch information
meaboutsoftware committed Apr 5, 2024
1 parent 9587955 commit e89d7a6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal sealed class TerminateBindingContractCommandHandler(
{
public async Task Handle(TerminateBindingContractCommand command, CancellationToken cancellationToken)
{
var contract = await bindingContractsRepository.GetByIdAsync(command.Id, cancellationToken) ??
var contract = await bindingContractsRepository.GetByContractIdAsync(command.Id, cancellationToken) ??
throw new ResourceNotFoundException(command.Id);
var terminatedAt = timeProvider.GetUtcNow();
contract.Terminate(terminatedAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public interface IBindingContractsRepository
{
Task<BindingContract?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);
Task<BindingContract?> GetByContractIdAsync(Guid contractId, CancellationToken cancellationToken = default);
Task AddAsync(BindingContract bindingContract, CancellationToken cancellationToken = default);
Task CommitAsync(CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
namespace EvolutionaryArchitecture.Fitnet.Contracts.Infrastructure.Database.Repositories;

using Core;
using Microsoft.EntityFrameworkCore;

internal sealed class BindingContractsRepository(ContractsPersistence persistence) : IBindingContractsRepository
{
public async Task<BindingContract?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default) =>
await persistence.BindingContracts.FindAsync([new ContractId(id)], cancellationToken);
public async Task<BindingContract?> GetByContractIdAsync(Guid contractId,
CancellationToken cancellationToken = default) =>
await persistence.BindingContracts.Where(bc => bc.ContractId == new ContractId(contractId))
.SingleOrDefaultAsync(cancellationToken: cancellationToken);

public async Task AddAsync(BindingContract bindingContract, CancellationToken cancellationToken = default)
{
Expand Down

0 comments on commit e89d7a6

Please sign in to comment.