diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/DomainServiceHelperTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/DomainServiceHelperTests.cs index d7bede8c..c55ac544 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/DomainServiceHelperTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/DomainServiceHelperTests.cs @@ -3,6 +3,7 @@ using Shared.EventStore.Aggregate; using Shouldly; using SimpleResults; +using TransactionProcessor.BusinessLogic.Common; using TransactionProcessor.BusinessLogic.Services; using Xunit; diff --git a/TransactionProcessor.BusinessLogic/Common/DomainServiceHelper.cs b/TransactionProcessor.BusinessLogic/Common/DomainServiceHelper.cs new file mode 100644 index 00000000..2e599241 --- /dev/null +++ b/TransactionProcessor.BusinessLogic/Common/DomainServiceHelper.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Shared.EventStore.Aggregate; +using Shared.Results; +using SimpleResults; + +namespace TransactionProcessor.BusinessLogic.Common; + +public static class DomainServiceHelper +{ + public static async Task> GetAggregateOrFailure(Func>> fetchFunc, + Guid aggregateId, + CancellationToken cancellationToken, + Boolean isNotFoundError = true) where TAggregate : Aggregate, new() + { + Result result = await fetchFunc(cancellationToken); + return result.IsFailed switch + { + true => DomainServiceHelper.HandleGetAggregateResult(result, aggregateId, isNotFoundError), + _ => Result.Success(result.Data) + }; + } + + public static Result HandleGetAggregateResult(Result result, Guid aggregateId, bool isNotFoundError = true) + where T : Aggregate, new() // Constraint: T is a subclass of Aggregate and has a parameterless constructor + { + if (result.IsFailed && result.Status != ResultStatus.NotFound) + { + return ResultHelpers.CreateFailure(result); + } + + if (result.Status == ResultStatus.NotFound && isNotFoundError) + { + return ResultHelpers.CreateFailure(result); + } + + T aggregate = result.Status switch + { + ResultStatus.NotFound => new T { AggregateId = aggregateId }, // Set AggregateId when creating a new instance + _ => result.Data + }; + + return Result.Success(aggregate); + } +} \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/Services/ContractDomainService.cs b/TransactionProcessor.BusinessLogic/Services/ContractDomainService.cs index 5be8f7d3..0312e255 100644 --- a/TransactionProcessor.BusinessLogic/Services/ContractDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/ContractDomainService.cs @@ -11,6 +11,7 @@ using Shared.Results; using SimpleResults; using TransactionProcessor.Aggregates; +using TransactionProcessor.BusinessLogic.Common; using TransactionProcessor.BusinessLogic.Requests; using TransactionProcessor.Models.Contract; diff --git a/TransactionProcessor.BusinessLogic/Services/EstateDomainService.cs b/TransactionProcessor.BusinessLogic/Services/EstateDomainService.cs index b5125f54..717689ee 100644 --- a/TransactionProcessor.BusinessLogic/Services/EstateDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/EstateDomainService.cs @@ -12,6 +12,7 @@ using Shared.Results; using SimpleResults; using TransactionProcessor.Aggregates; +using TransactionProcessor.BusinessLogic.Common; using TransactionProcessor.BusinessLogic.Requests; namespace TransactionProcessor.BusinessLogic.Services diff --git a/TransactionProcessor.BusinessLogic/Services/FloatDomainService.cs b/TransactionProcessor.BusinessLogic/Services/FloatDomainService.cs index 73dd5fec..e7a1136b 100644 --- a/TransactionProcessor.BusinessLogic/Services/FloatDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/FloatDomainService.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Shared.Results; using SimpleResults; +using TransactionProcessor.BusinessLogic.Common; using TransactionProcessor.BusinessLogic.Requests; namespace TransactionProcessor.BusinessLogic.Services @@ -33,67 +34,14 @@ public FloatDomainService(Func aggregateService) { this.AggregateService = aggregateService(); } - - private async Task ApplyFloatUpdates(Func action, Guid floatId, CancellationToken cancellationToken, Boolean isNotFoundError = true) - { - try - { - Result getFloatResult = await this.AggregateService.GetLatest(floatId, cancellationToken); - Result floatAggregateResult = DomainServiceHelper.HandleGetAggregateResult(getFloatResult, floatId, isNotFoundError); - - if (floatAggregateResult.IsFailed) - return ResultHelpers.CreateFailure(floatAggregateResult); - - FloatAggregate floatAggregate = floatAggregateResult.Data; - - Result result = action(floatAggregate); - if (result.IsFailed) - return ResultHelpers.CreateFailure(result); - - Result saveResult = await this.AggregateService.Save(floatAggregate, cancellationToken); - if (saveResult.IsFailed) - return ResultHelpers.CreateFailure(saveResult); - - return Result.Success(); - } - catch (Exception ex) - { - return Result.Failure(ex.GetExceptionMessages()); - } - } - - private async Task ApplyFloatActivityUpdates(Func action, Guid floatId, CancellationToken cancellationToken, Boolean isNotFoundError = true) - { - try - { - Result getFloatResult = await this.AggregateService.GetLatest(floatId, cancellationToken); - Result floatActivityAggregateResult = DomainServiceHelper.HandleGetAggregateResult(getFloatResult, floatId, isNotFoundError); - - if (floatActivityAggregateResult.IsFailed) - return ResultHelpers.CreateFailure(floatActivityAggregateResult); - - FloatActivityAggregate floatActivityAggregate = floatActivityAggregateResult.Data; - - Result result = action(floatActivityAggregate); - if (result.IsFailed) - return ResultHelpers.CreateFailure(result); - - Result saveResult = await this.AggregateService.Save(floatActivityAggregate, cancellationToken); - if (saveResult.IsFailed) - return ResultHelpers.CreateFailure(saveResult); - - return Result.Success(); - } - catch (Exception ex) - { - return Result.Failure(ex.GetExceptionMessages()); - } - } - - + private async Task ValidateEstate(Guid estateId, CancellationToken cancellationToken) { - Result getEstateResult= await this.AggregateService.Get(estateId, cancellationToken); + Result getEstateResult= await DomainServiceHelper.GetAggregateOrFailure( + (token) => this.AggregateService.Get(estateId, token), + estateId, + cancellationToken, + isNotFoundError: true); if (getEstateResult.IsFailed) { return ResultHelpers.CreateFailure(getEstateResult); @@ -103,11 +51,12 @@ private async Task ValidateEstate(Guid estateId, CancellationToken cance private async Task ValidateContractProduct(Guid estateId, Guid contractId, Guid productId, CancellationToken cancellationToken) { - Result getContractResult = await this.AggregateService.Get(contractId, cancellationToken); - if (getContractResult.IsFailed) - { - return ResultHelpers.CreateFailure(getContractResult); - } + Result getContractResult = await DomainServiceHelper.GetAggregateOrFailure( + (token) => this.AggregateService.Get(contractId, token), + contractId, + cancellationToken, + isNotFoundError: true); + ContractAggregate contractAggregate = getContractResult.Data; Models.Contract.Contract contract = contractAggregate.GetContract(); Boolean productExists = contract.Products.Any(cp => cp.ContractProductId == productId); @@ -120,105 +69,118 @@ private async Task ValidateContractProduct(Guid estateId, Guid contractI public async Task CreateFloatForContractProduct(FloatCommands.CreateFloatForContractProductCommand command, CancellationToken cancellationToken){ - - Result validateEstateResult = await this.ValidateEstate(command.EstateId, cancellationToken); - if (validateEstateResult.IsFailed) { - return ResultHelpers.CreateFailure(validateEstateResult); - } - Result validateProductResult = await this.ValidateContractProduct(command.EstateId, command.ContractId, command.ProductId, cancellationToken); - if (validateProductResult.IsFailed) { - return ResultHelpers.CreateFailure(validateProductResult); - } + try { + Result validateEstateResult = await this.ValidateEstate(command.EstateId, cancellationToken); + if (validateEstateResult.IsFailed) { + return ResultHelpers.CreateFailure(validateEstateResult); + } - // Generate the float id - Guid floatId = IdGenerationService.GenerateFloatAggregateId(command.EstateId, command.ContractId, command.ProductId); + Result validateProductResult = await this.ValidateContractProduct(command.EstateId, command.ContractId, command.ProductId, cancellationToken); + if (validateProductResult.IsFailed) { + return ResultHelpers.CreateFailure(validateProductResult); + } + + // Generate the float id + Guid floatId = IdGenerationService.GenerateFloatAggregateId(command.EstateId, command.ContractId, command.ProductId); + + Result getFloatResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(floatId, ct), floatId, cancellationToken); + if (getFloatResult.IsFailed) + return ResultHelpers.CreateFailure(getFloatResult); + + FloatAggregate floatAggregate = getFloatResult.Data; - Result result = await this.ApplyFloatUpdates((FloatAggregate floatAggregate) => { floatAggregate.CreateFloat(command.EstateId, command.ContractId, command.ProductId, command.CreateDateTime); - return Result.Success(); - }, floatId,cancellationToken, false); - return result; + Result saveResult = await this.AggregateService.Save(floatAggregate, cancellationToken); + if (saveResult.IsFailed) + return ResultHelpers.CreateFailure(saveResult); + return saveResult; + } + catch (Exception ex) { + return Result.Failure(ex.GetExceptionMessages()); + } } public async Task RecordCreditPurchase(FloatCommands.RecordCreditPurchaseForFloatCommand command, CancellationToken cancellationToken){ - Result result = await this.ApplyFloatUpdates((FloatAggregate floatAggregate) => { + + try + { + Result getFloatResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.FloatId, ct), command.FloatId, cancellationToken); + if (getFloatResult.IsFailed) + return ResultHelpers.CreateFailure(getFloatResult); + + FloatAggregate floatAggregate = getFloatResult.Data; + floatAggregate.RecordCreditPurchase(command.PurchaseDateTime, command.CreditAmount, command.CostPrice); - return Result.Success(); - }, command.FloatId, cancellationToken); - return result; + Result saveResult = await this.AggregateService.Save(floatAggregate, cancellationToken); + if (saveResult.IsFailed) + return ResultHelpers.CreateFailure(saveResult); + return saveResult; + } + catch (Exception ex) + { + return Result.Failure(ex.GetExceptionMessages()); + } } public async Task RecordCreditPurchase(FloatActivityCommands.RecordCreditPurchaseCommand command, CancellationToken cancellationToken) { - // Generate the id for the activity aggregate - Guid floatActivityAggregateId = IdGenerationService.GenerateFloatActivityAggregateId(command.EstateId, command.FloatId, command.CreditPurchasedDateTime.Date); + try + { + Guid floatActivityAggregateId = IdGenerationService.GenerateFloatActivityAggregateId(command.EstateId, command.FloatId, command.CreditPurchasedDateTime.Date); + + Result getFloatActivityResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(floatActivityAggregateId, ct), floatActivityAggregateId, cancellationToken); + if (getFloatActivityResult.IsFailed) + return ResultHelpers.CreateFailure(getFloatActivityResult); + + FloatActivityAggregate floatActivityAggregate = getFloatActivityResult.Data; + + floatActivityAggregate.RecordCreditPurchase(command.EstateId, command.CreditPurchasedDateTime, command.Amount, command.CreditId); - Result result = await ApplyFloatActivityUpdates((floatAggregate) => { - floatAggregate.RecordCreditPurchase(command.EstateId, command.CreditPurchasedDateTime, command.Amount, command.CreditId); - return Result.Success(); - }, floatActivityAggregateId, cancellationToken,false); - return result; + Result saveResult = await this.AggregateService.Save(floatActivityAggregate, cancellationToken); + if (saveResult.IsFailed) + return ResultHelpers.CreateFailure(saveResult); + return saveResult; + } + catch (Exception ex) + { + return Result.Failure(ex.GetExceptionMessages()); + } } public async Task RecordTransaction(FloatActivityCommands.RecordTransactionCommand command, CancellationToken cancellationToken) { - - Result getTransactionResult = await this.AggregateService.GetLatest(command.TransactionId, cancellationToken); - if (getTransactionResult.IsFailed) - return ResultHelpers.CreateFailure(getTransactionResult); - Guid floatId = IdGenerationService.GenerateFloatAggregateId(command.EstateId, getTransactionResult.Data.ContractId, getTransactionResult.Data.ProductId); + try { + Result getTransactionResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.TransactionId, ct), command.TransactionId, cancellationToken); + if (getTransactionResult.IsFailed) + return ResultHelpers.CreateFailure(getTransactionResult); - // Generate the id for the activity aggregate - Guid floatActivityAggregateId = IdGenerationService.GenerateFloatActivityAggregateId(command.EstateId, floatId, getTransactionResult.Data.TransactionDateTime.Date); - Result result = await ApplyFloatActivityUpdates((floatAggregate) => { - floatAggregate.RecordTransactionAgainstFloat(command.EstateId, getTransactionResult.Data.TransactionDateTime, getTransactionResult.Data.TransactionAmount.GetValueOrDefault(), command.TransactionId); - return Result.Success(); - }, floatActivityAggregateId, cancellationToken, false); - return result; - } - } + Guid floatId = IdGenerationService.GenerateFloatAggregateId(command.EstateId, getTransactionResult.Data.ContractId, getTransactionResult.Data.ProductId); - public static class DomainServiceHelper - { - public static async Task> GetAggregateOrFailure(Func>> fetchFunc, - Guid aggregateId, - CancellationToken cancellationToken, - Boolean isNotFoundError = true) where TAggregate : Aggregate, new() - { - Result result = await fetchFunc(cancellationToken); - return result.IsFailed switch - { - true => DomainServiceHelper.HandleGetAggregateResult(result, aggregateId, isNotFoundError), - _ => Result.Success(result.Data) - }; - } + // Generate the id for the activity aggregate + Guid floatActivityAggregateId = IdGenerationService.GenerateFloatActivityAggregateId(command.EstateId, floatId, getTransactionResult.Data.TransactionDateTime.Date); - public static Result HandleGetAggregateResult(Result result, Guid aggregateId, bool isNotFoundError = true) - where T : Aggregate, new() // Constraint: T is a subclass of Aggregate and has a parameterless constructor - { - if (result.IsFailed && result.Status != ResultStatus.NotFound) - { - return ResultHelpers.CreateFailure(result); - } + Result getFloatActivityResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(floatActivityAggregateId, ct), floatActivityAggregateId, cancellationToken); + if (getFloatActivityResult.IsFailed) + return ResultHelpers.CreateFailure(getFloatActivityResult); - if (result.Status == ResultStatus.NotFound && isNotFoundError) - { - return ResultHelpers.CreateFailure(result); - } + FloatActivityAggregate floatActivityAggregate = getFloatActivityResult.Data; - T aggregate = result.Status switch - { - ResultStatus.NotFound => new T { AggregateId = aggregateId }, // Set AggregateId when creating a new instance - _ => result.Data - }; + floatActivityAggregate.RecordTransactionAgainstFloat(command.EstateId, getTransactionResult.Data.TransactionDateTime, getTransactionResult.Data.TransactionAmount.GetValueOrDefault(), command.TransactionId); - return Result.Success(aggregate); + Result saveResult = await this.AggregateService.Save(floatActivityAggregate, cancellationToken); + if (saveResult.IsFailed) + return ResultHelpers.CreateFailure(saveResult); + return saveResult; + } + catch (Exception ex) { + return Result.Failure(ex.GetExceptionMessages()); + } } } } diff --git a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs index 92313077..7ac4c9b1 100644 --- a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs @@ -15,6 +15,7 @@ using System.Threading.Tasks; using SecurityService.DataTransferObjects.Responses; using TransactionProcessor.Aggregates; +using TransactionProcessor.BusinessLogic.Common; using TransactionProcessor.BusinessLogic.Requests; using TransactionProcessor.Database.Entities; using TransactionProcessor.Models.Estate; @@ -71,21 +72,9 @@ public MerchantDomainService(Func aggregateService, #region Methods - //private async Task> GetAggregateOrFailure(Func>> fetchFunc, - // Guid aggregateId, - // CancellationToken cancellationToken, - // Boolean isNotFoundError = true) where TAggregate : Aggregate, new() - //{ - // Result result = await fetchFunc(cancellationToken); - // return result.IsFailed switch { - // true => DomainServiceHelper.HandleGetAggregateResult(result, aggregateId, isNotFoundError), - // _ => Result.Success(result.Data) - // }; - //} - public async Task AddDeviceToMerchant(MerchantCommands.AddMerchantDeviceCommand command, CancellationToken cancellationToken) { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -294,7 +283,7 @@ public async Task MakeMerchantDeposit(MerchantCommands.MakeMerchantDepos { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -310,7 +299,7 @@ public async Task MakeMerchantDeposit(MerchantCommands.MakeMerchantDepos if (validateResult.IsFailed) return ResultHelpers.CreateFailure(validateResult); - Result getDepositListResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken, false).ConfigureAwait(false); + Result getDepositListResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken, false); if (getDepositListResult.IsFailed) return ResultHelpers.CreateFailure(getDepositListResult); @@ -346,7 +335,7 @@ public async Task MakeMerchantWithdrawal(MerchantCommands.MakeMerchantWi try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -362,7 +351,7 @@ public async Task MakeMerchantWithdrawal(MerchantCommands.MakeMerchantWi if (validateResult.IsFailed) return ResultHelpers.CreateFailure(validateResult); - Result getDepositListResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken).ConfigureAwait(false); + Result getDepositListResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); if (getDepositListResult.IsFailed) return ResultHelpers.CreateFailure(getDepositListResult); @@ -407,7 +396,7 @@ public async Task MakeMerchantWithdrawal(MerchantCommands.MakeMerchantWi public async Task AddContractToMerchant(MerchantCommands.AddMerchantContractCommand command, CancellationToken cancellationToken) { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -449,7 +438,7 @@ public async Task UpdateMerchant(MerchantCommands.UpdateMerchantCommand { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -486,7 +475,7 @@ public async Task AddMerchantAddress(MerchantCommands.AddMerchantAddress { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -527,7 +516,7 @@ public async Task UpdateMerchantAddress(MerchantCommands.UpdateMerchantA { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -569,7 +558,7 @@ public async Task AddMerchantContact(MerchantCommands.AddMerchantContact { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -604,7 +593,7 @@ public async Task AddMerchantContact(MerchantCommands.AddMerchantContact public async Task UpdateMerchantContact(MerchantCommands.UpdateMerchantContactCommand command, CancellationToken cancellationToken) { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -636,7 +625,7 @@ public async Task UpdateMerchantContact(MerchantCommands.UpdateMerchantC public async Task RemoveOperatorFromMerchant(MerchantCommands.RemoveOperatorFromMerchantCommand command, CancellationToken cancellationToken) { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -668,7 +657,7 @@ public async Task RemoveContractFromMerchant(MerchantCommands.RemoveMerc { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -720,7 +709,7 @@ public async Task SwapMerchantDevice(MerchantCommands.SwapMerchantDevice { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); diff --git a/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs b/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs index f2f03d34..aaa060ac 100644 --- a/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/OperatorDomainService.cs @@ -8,6 +8,7 @@ using Shared.Results; using SimpleResults; using TransactionProcessor.Aggregates; +using TransactionProcessor.BusinessLogic.Common; using TransactionProcessor.BusinessLogic.Requests; namespace TransactionProcessor.BusinessLogic.Services @@ -30,7 +31,7 @@ public OperatorDomainService(Func aggregateService) { public async Task CreateOperator(OperatorCommands.CreateOperatorCommand command, CancellationToken cancellationToken) { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); @@ -66,7 +67,7 @@ public async Task UpdateOperator(OperatorCommands.UpdateOperatorCommand { try { - Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken).ConfigureAwait(false); + Result estateResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.EstateId, ct), command.EstateId, cancellationToken); if (estateResult.IsFailed) return ResultHelpers.CreateFailure(estateResult); diff --git a/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs b/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs index 952a78f9..cb5f3db7 100644 --- a/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/VoucherDomainService.cs @@ -1,5 +1,6 @@ using Shared.Results; using TransactionProcessor.Aggregates; +using TransactionProcessor.BusinessLogic.Common; using TransactionProcessor.Database.Contexts; using TransactionProcessor.DataTransferObjects.Responses.Estate; using TransactionProcessor.Models.Estate;