From fd53839fd84e71417b0b93f8f7a1ad2f0831f0ac Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 12 Nov 2024 17:12:56 +0000 Subject: [PATCH 1/2] project converted to result flows --- .../MediatorTests.cs | 71 ++++--- .../RequestHandlerTests.cs | 83 ++++---- .../RequestTests.cs | 111 ----------- .../ProcessLogonTransactionRequestHandler.cs | 66 ++++--- .../ProcessReconciliationRequestHandler.cs | 58 ------ .../ProcessSaleTransactionRequestHandler.cs | 62 ------ .../VersionCheckRequestHandler.cs | 25 ++- .../RequestHandlers/VoucherRequestHandler.cs | 33 +--- .../Requests/GetVoucherRequest.cs | 142 -------------- .../ProcessLogonTransactionRequest.cs | 112 ----------- .../Requests/ProcessReconciliationRequest.cs | 127 ------------ .../Requests/ProcessSaleTransactionRequest.cs | 185 ------------------ .../Requests/TransactionCommands.cs | 36 ++++ .../Requests/VersionCheckCommands.cs | 9 + .../Requests/VersionCheckRequest.cs | 51 ----- .../Requests/VoucherCommands.cs | 10 + .../Requests/VoucherQueries.cs | 11 ++ ...ansactionProcessorACLApplicationService.cs | 7 +- ...ansactionProcessorACLApplicationService.cs | 58 +++--- ...ansactionProcessorACL.BusinessLogic.csproj | 8 +- .../Common/DockerHelper.cs | 2 +- .../Shared/ACLSteps.cs | 12 +- .../Shared/SharedSteps.cs | 5 + ...actionProcessorACL.IntegrationTests.csproj | 14 +- TransactionProcessorACL.Testing/TestData.cs | 15 +- .../TransactionProcessorACL.Testing.csproj | 6 +- .../TransactionProcessorACLWebFactory.cs | 2 +- .../Bootstrapper/MediatorRegistry.cs | 24 ++- .../Controllers/ResultExtensions.cs | 63 ++++++ .../Controllers/TransactionController.cs | 57 +++--- .../Controllers/VoucherController.cs | 54 +++-- .../TransactionProcessorACL.csproj | 2 +- 32 files changed, 408 insertions(+), 1113 deletions(-) delete mode 100644 TransactionProcessorACL.BusinessLogic.Tests/RequestTests.cs delete mode 100644 TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessReconciliationRequestHandler.cs delete mode 100644 TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessSaleTransactionRequestHandler.cs delete mode 100644 TransactionProcessorACL.BusinessLogic/Requests/GetVoucherRequest.cs delete mode 100644 TransactionProcessorACL.BusinessLogic/Requests/ProcessLogonTransactionRequest.cs delete mode 100644 TransactionProcessorACL.BusinessLogic/Requests/ProcessReconciliationRequest.cs delete mode 100644 TransactionProcessorACL.BusinessLogic/Requests/ProcessSaleTransactionRequest.cs create mode 100644 TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs create mode 100644 TransactionProcessorACL.BusinessLogic/Requests/VersionCheckCommands.cs delete mode 100644 TransactionProcessorACL.BusinessLogic/Requests/VersionCheckRequest.cs create mode 100644 TransactionProcessorACL.BusinessLogic/Requests/VoucherCommands.cs create mode 100644 TransactionProcessorACL.BusinessLogic/Requests/VoucherQueries.cs create mode 100644 TransactionProcessorACL/Controllers/ResultExtensions.cs diff --git a/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs b/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs index 9d8a0ba..03a6e83 100644 --- a/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs +++ b/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using SimpleResults; using TransactionProcessorACL.Testing; using Xunit; @@ -26,12 +27,12 @@ public class MediatorTests public MediatorTests() { - this.Requests.Add(TestData.ProcessLogonTransactionRequest); - this.Requests.Add(TestData.ProcessReconciliationRequest); - this.Requests.Add(TestData.ProcessSaleTransactionRequest); - this.Requests.Add(TestData.VersionCheckRequest); - this.Requests.Add(TestData.GetVoucherRequest); - this.Requests.Add(TestData.RedeemVoucherRequest); + this.Requests.Add(TestData.ProcessLogonTransactionCommand); + this.Requests.Add(TestData.ProcessReconciliationCommand); + this.Requests.Add(TestData.ProcessSaleTransactionCommand); + this.Requests.Add(TestData.VersionCheckCommand); + this.Requests.Add(TestData.GetVoucherQuery); + this.Requests.Add(TestData.RedeemVoucherCommand); } [Fact] @@ -99,38 +100,32 @@ private void AddTestRegistrations(ServiceRegistry services, public class DummyTransactionProcessorACLApplicationService : ITransactionProcessorACLApplicationService { - public async Task ProcessLogonTransaction(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String transactionNumber, - String deviceIdentifier, - CancellationToken cancellationToken) { - return new ProcessLogonTransactionResponse(); - } - - public async Task ProcessSaleTransaction(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String transactionNumber, - String deviceIdentifier, - Guid operatorId, - String customerEmailAddress, - Guid contractId, - Guid productId, - Dictionary additionalRequestMetadata, - CancellationToken cancellationToken) { - return new ProcessSaleTransactionResponse(); - } - - public async Task ProcessReconciliation(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String deviceIdentifier, - Int32 transactionCount, - Decimal transactionValue, - CancellationToken cancellationToken) { - return new ProcessReconciliationResponse(); - } + public async Task> ProcessLogonTransaction(Guid estateId, + Guid merchantId, + DateTime transactionDateTime, + String transactionNumber, + String deviceIdentifier, + CancellationToken cancellationToken) => Result.Success(new ProcessLogonTransactionResponse()); + + public async Task> ProcessSaleTransaction(Guid estateId, + Guid merchantId, + DateTime transactionDateTime, + String transactionNumber, + String deviceIdentifier, + Guid operatorId, + String customerEmailAddress, + Guid contractId, + Guid productId, + Dictionary additionalRequestMetadata, + CancellationToken cancellationToken) => Result.Success(new ProcessSaleTransactionResponse()); + + public async Task> ProcessReconciliation(Guid estateId, + Guid merchantId, + DateTime transactionDateTime, + String deviceIdentifier, + Int32 transactionCount, + Decimal transactionValue, + CancellationToken cancellationToken) => Result.Success(new ProcessReconciliationResponse()); public async Task GetVoucher(Guid estateId, Guid contractId, diff --git a/TransactionProcessorACL.BusinessLogic.Tests/RequestHandlerTests.cs b/TransactionProcessorACL.BusinessLogic.Tests/RequestHandlerTests.cs index 952c3c2..5e5f298 100644 --- a/TransactionProcessorACL.BusinessLogic.Tests/RequestHandlerTests.cs +++ b/TransactionProcessorACL.BusinessLogic.Tests/RequestHandlerTests.cs @@ -1,3 +1,5 @@ +using SimpleResults; + namespace TransactionProcessorACL.BusinesssLogic.Tests { using System; @@ -15,6 +17,7 @@ namespace TransactionProcessorACL.BusinesssLogic.Tests using Shouldly; using Testing; using Xunit; + using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; /// /// @@ -51,16 +54,17 @@ public async Task ProcessLogonTransactionRequestHandler_Handle_RequestIsHandled( It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(TestData.ProcessLogonTransactionResponse); - ProcessLogonTransactionRequestHandler requestHandler = new ProcessLogonTransactionRequestHandler(applicationService.Object); + TransactionRequestHandler requestHandler = new TransactionRequestHandler(applicationService.Object); - ProcessLogonTransactionRequest request = TestData.ProcessLogonTransactionRequest; - ProcessLogonTransactionResponse response = await requestHandler.Handle(request, CancellationToken.None); + TransactionCommands.ProcessLogonTransactionCommand command = TestData.ProcessLogonTransactionCommand; + Result result = await requestHandler.Handle(command, CancellationToken.None); - response.ShouldNotBeNull(); - response.ResponseCode.ShouldBe(TestData.ResponseCode); - response.ResponseMessage.ShouldBe(TestData.ResponseMessage); - response.EstateId.ShouldBe(TestData.EstateId); - response.MerchantId.ShouldBe(TestData.MerchantId); + result.IsSuccess.ShouldBeTrue(); + result.Data.ShouldNotBeNull(); + result.Data.ResponseCode.ShouldBe(TestData.ResponseCode); + result.Data.ResponseMessage.ShouldBe(TestData.ResponseMessage); + result.Data.EstateId.ShouldBe(TestData.EstateId); + result.Data.MerchantId.ShouldBe(TestData.MerchantId); } [Fact] @@ -80,14 +84,15 @@ public async Task ProcessSaleTransactionRequestHandler_Handle_RequestIsHandled() It.IsAny>(), It.IsAny())).ReturnsAsync(TestData.ProcessSaleTransactionResponse); - ProcessSaleTransactionRequestHandler requestHandler = new ProcessSaleTransactionRequestHandler(applicationService.Object); + TransactionRequestHandler requestHandler = new TransactionRequestHandler(applicationService.Object); - ProcessSaleTransactionRequest request = TestData.ProcessSaleTransactionRequest; - ProcessSaleTransactionResponse response = await requestHandler.Handle(request, CancellationToken.None); + TransactionCommands.ProcessSaleTransactionCommand command = TestData.ProcessSaleTransactionCommand; + Result result = await requestHandler.Handle(command, CancellationToken.None); - response.ShouldNotBeNull(); - response.ResponseCode.ShouldBe(TestData.ResponseCode); - response.ResponseMessage.ShouldBe(TestData.ResponseMessage); + result.IsSuccess.ShouldBeTrue(); + result.Data.ShouldNotBeNull(); + result.Data.ResponseCode.ShouldBe(TestData.ResponseCode); + result.Data.ResponseMessage.ShouldBe(TestData.ResponseMessage); } [Fact] @@ -102,16 +107,17 @@ public async Task ProcessReconciliationRequestHandler_Handle_RequestIsHandled() It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(TestData.ProcessReconciliationResponse); - ProcessReconciliationRequestHandler requestHandler = new ProcessReconciliationRequestHandler(applicationService.Object); + TransactionRequestHandler requestHandler = new TransactionRequestHandler(applicationService.Object); - ProcessReconciliationRequest request = TestData.ProcessReconciliationRequest; - ProcessReconciliationResponse response = await requestHandler.Handle(request, CancellationToken.None); + TransactionCommands.ProcessReconciliationCommand command = TestData.ProcessReconciliationCommand; + Result result = await requestHandler.Handle(command, CancellationToken.None); - response.ShouldNotBeNull(); - response.ResponseCode.ShouldBe(TestData.ResponseCode); - response.ResponseMessage.ShouldBe(TestData.ResponseMessage); - response.EstateId.ShouldBe(TestData.EstateId); - response.MerchantId.ShouldBe(TestData.MerchantId); + result.IsSuccess.ShouldBeTrue(); + result.Data.ShouldNotBeNull(); + result.Data.ResponseCode.ShouldBe(TestData.ResponseCode); + result.Data.ResponseMessage.ShouldBe(TestData.ResponseMessage); + result.Data.EstateId.ShouldBe(TestData.EstateId); + result.Data.MerchantId.ShouldBe(TestData.MerchantId); } [Fact] @@ -119,35 +125,30 @@ public async Task VersionCheckRequestHandler_Handle_RequestIsHandled() { VersionCheckRequestHandler requestHandler = new VersionCheckRequestHandler(); - VersionCheckRequest request = TestData.VersionCheckRequest; - Should.NotThrow(async () => - { - await requestHandler.Handle(request, CancellationToken.None); - }); + VersionCheckCommands.VersionCheckCommand command = TestData.VersionCheckCommand; + var result = await requestHandler.Handle(command, CancellationToken.None); + result.IsSuccess.ShouldBeTrue(); } [Fact] public async Task VersionCheckRequestHandler_Handle_OldVersion_ErrorThrown() { VersionCheckRequestHandler requestHandler = new VersionCheckRequestHandler(); - - VersionCheckRequest request = VersionCheckRequest.Create(TestData.OldApplicationVersion); - Should.Throw(async () => - { - await requestHandler.Handle(request, CancellationToken.None); - }); + + VersionCheckCommands.VersionCheckCommand command = new(TestData.OldApplicationVersion); + var result = await requestHandler.Handle(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + result.Status.ShouldBe(ResultStatus.Conflict); } [Fact] public async Task VersionCheckRequestHandler_Handle_NewerVersionBuildNumber_RequestIsHandled() { VersionCheckRequestHandler requestHandler = new VersionCheckRequestHandler(); - - VersionCheckRequest request = VersionCheckRequest.Create(TestData.NewerApplicationVersion); - Should.NotThrow(async () => - { - await requestHandler.Handle(request, CancellationToken.None); - }); + + VersionCheckCommands.VersionCheckCommand command = new(TestData.NewerApplicationVersion); + var result = await requestHandler.Handle(command, CancellationToken.None); + result.IsSuccess.ShouldBeTrue(); ; } [Fact] @@ -158,7 +159,7 @@ public async Task VoucherRequestHandler_GetVoucherRequest_Handle_RequestIsHandle Should.NotThrow(async () => { - await requestHandler.Handle(TestData.GetVoucherRequest, CancellationToken.None); + await requestHandler.Handle(TestData.GetVoucherQuery, CancellationToken.None); }); } @@ -170,7 +171,7 @@ public async Task VoucherRequestHandler_RedeemVoucherRequest_Handle_RequestIsHan Should.NotThrow(async () => { - await requestHandler.Handle(TestData.RedeemVoucherRequest, CancellationToken.None); + await requestHandler.Handle(TestData.RedeemVoucherCommand, CancellationToken.None); }); } diff --git a/TransactionProcessorACL.BusinessLogic.Tests/RequestTests.cs b/TransactionProcessorACL.BusinessLogic.Tests/RequestTests.cs deleted file mode 100644 index 8c0364d..0000000 --- a/TransactionProcessorACL.BusinessLogic.Tests/RequestTests.cs +++ /dev/null @@ -1,111 +0,0 @@ -namespace TransactionProcessorACL.BusinesssLogic.Tests -{ - using BusinessLogic.Requests; - using Shouldly; - using Testing; - using Xunit; - - /// - /// - /// - public class RequestTests - { - #region Methods - - /// - /// Processes the logon transaction request can be created is created. - /// - [Fact] - public void ProcessLogonTransactionRequest_CanBeCreated_IsCreated() - { - ProcessLogonTransactionRequest request = ProcessLogonTransactionRequest.Create(TestData.EstateId, - TestData.MerchantId, - TestData.TransactionDateTime, - TestData.TransactionNumber, - TestData.DeviceIdentifier); - - request.EstateId.ShouldBe(TestData.EstateId); - request.MerchantId.ShouldBe(TestData.MerchantId); - request.TransactionDateTime.ShouldBe(TestData.TransactionDateTime); - request.TransactionNumber.ShouldBe(TestData.TransactionNumber); - request.DeviceIdentifier.ShouldBe(TestData.DeviceIdentifier); - } - - [Fact] - public void ProcessSaleTransactionRequest_CanBeCreated_IsCreated() - { - ProcessSaleTransactionRequest request = ProcessSaleTransactionRequest.Create(TestData.EstateId, - TestData.MerchantId, - TestData.TransactionDateTime, - TestData.TransactionNumber, - TestData.DeviceIdentifier, - TestData.OperatorId, - TestData.CustomerEmailAddress, - TestData.ContractId, - TestData.ProductId, - TestData.AdditionalRequestMetadata); - - request.EstateId.ShouldBe(TestData.EstateId); - request.MerchantId.ShouldBe(TestData.MerchantId); - request.TransactionDateTime.ShouldBe(TestData.TransactionDateTime); - request.TransactionNumber.ShouldBe(TestData.TransactionNumber); - request.DeviceIdentifier.ShouldBe(TestData.DeviceIdentifier); - request.OperatorId.ShouldBe(TestData.OperatorId); - request.CustomerEmailAddress.ShouldBe(TestData.CustomerEmailAddress); - request.ContractId.ShouldBe(TestData.ContractId); - request.ProductId.ShouldBe(TestData.ProductId); - request.AdditionalRequestMetadata.ShouldBe(TestData.AdditionalRequestMetadata); - } - - [Fact] - public void ProcessReconciliationRequest_CanBeCreated_IsCreated() - { - ProcessReconciliationRequest request = ProcessReconciliationRequest.Create(TestData.EstateId, - TestData.MerchantId, - TestData.TransactionDateTime, - TestData.DeviceIdentifier, - TestData.ReconciliationTransactionCount, - TestData.ReconciliationTransactionValue); - - request.EstateId.ShouldBe(TestData.EstateId); - request.MerchantId.ShouldBe(TestData.MerchantId); - request.TransactionDateTime.ShouldBe(TestData.TransactionDateTime); - request.DeviceIdentifier.ShouldBe(TestData.DeviceIdentifier); - request.TransactionCount.ShouldBe(TestData.ReconciliationTransactionCount); - request.TransactionValue.ShouldBe(TestData.ReconciliationTransactionValue); - } - - [Fact] - public void VersionCheckRequest_CanBeCreated_IsCreated() - { - VersionCheckRequest request = VersionCheckRequest.Create(TestData.ApplicationVersion); - - request.VersionNumber.ShouldBe(TestData.ApplicationVersion); - } - - /// - /// Processes the logon transaction request can be created is created. - /// - [Fact] - public void GetVoucherRequest_CanBeCreated_IsCreated() - { - GetVoucherRequest request = GetVoucherRequest.Create(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); - - request.EstateId.ShouldBe(TestData.EstateId); - request.ContractId.ShouldBe(TestData.ContractId); - request.VoucherCode.ShouldBe(TestData.VoucherCode); - } - - [Fact] - public void RedeemVoucherRequest_CanBeCreated_IsCreated() - { - RedeemVoucherRequest request = RedeemVoucherRequest.Create(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); - - request.EstateId.ShouldBe(TestData.EstateId); - request.ContractId.ShouldBe(TestData.ContractId); - request.VoucherCode.ShouldBe(TestData.VoucherCode); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessLogonTransactionRequestHandler.cs b/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessLogonTransactionRequestHandler.cs index ea3b927..c70025e 100644 --- a/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessLogonTransactionRequestHandler.cs +++ b/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessLogonTransactionRequestHandler.cs @@ -1,4 +1,6 @@ -namespace TransactionProcessorACL.BusinessLogic.RequestHandlers +using SimpleResults; + +namespace TransactionProcessorACL.BusinessLogic.RequestHandlers { using System.Threading; using System.Threading.Tasks; @@ -10,9 +12,11 @@ /// /// /// - /// /// - public class ProcessLogonTransactionRequestHandler : IRequestHandler + /// + public class TransactionRequestHandler : IRequestHandler>, + IRequestHandler>, + IRequestHandler> { #region Fields @@ -25,11 +29,7 @@ public class ProcessLogonTransactionRequestHandler : IRequestHandler - /// Initializes a new instance of the class. - /// - /// The application service. - public ProcessLogonTransactionRequestHandler(ITransactionProcessorACLApplicationService applicationService) + public TransactionRequestHandler(ITransactionProcessorACLApplicationService applicationService) { this.ApplicationService = applicationService; } @@ -38,25 +38,45 @@ public ProcessLogonTransactionRequestHandler(ITransactionProcessorACLApplication #region Methods - /// - /// Handles the specified request. - /// - /// The request. - /// The cancellation token. - /// - /// Response from the request - /// - public async Task Handle(ProcessLogonTransactionRequest request, - CancellationToken cancellationToken) + public async Task> Handle(TransactionCommands.ProcessLogonTransactionCommand command, + CancellationToken cancellationToken) { - return await this.ApplicationService.ProcessLogonTransaction(request.EstateId, - request.MerchantId, - request.TransactionDateTime, - request.TransactionNumber, - request.DeviceIdentifier, + return await this.ApplicationService.ProcessLogonTransaction(command.EstateId, + command.MerchantId, + command.TransactionDateTime, + command.TransactionNumber, + command.DeviceIdentifier, cancellationToken); } + public async Task> Handle(TransactionCommands.ProcessReconciliationCommand command, + CancellationToken cancellationToken) + { + return await this.ApplicationService.ProcessReconciliation(command.EstateId, + command.MerchantId, + command.TransactionDateTime, + command.DeviceIdentifier, + command.TransactionCount, + command.TransactionValue, + cancellationToken); + } + + public async Task> Handle(TransactionCommands.ProcessSaleTransactionCommand command, + CancellationToken cancellationToken) + { + return await this.ApplicationService.ProcessSaleTransaction(command.EstateId, + command.MerchantId, + command.TransactionDateTime, + command.TransactionNumber, + command.DeviceIdentifier, + command.OperatorId, + command.CustomerEmailAddress, + command.ContractId, + command.ProductId, + command.AdditionalRequestMetadata, + cancellationToken); + } + #endregion } } \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessReconciliationRequestHandler.cs b/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessReconciliationRequestHandler.cs deleted file mode 100644 index 7976ee3..0000000 --- a/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessReconciliationRequestHandler.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace TransactionProcessorACL.BusinessLogic.RequestHandlers -{ - using System.Threading; - using System.Threading.Tasks; - using MediatR; - using Models; - using Requests; - using Services; - - public class ProcessReconciliationRequestHandler : IRequestHandler - { - #region Fields - - /// - /// The application service - /// - private readonly ITransactionProcessorACLApplicationService ApplicationService; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The application service. - public ProcessReconciliationRequestHandler(ITransactionProcessorACLApplicationService applicationService) - { - this.ApplicationService = applicationService; - } - - #endregion - - #region Methods - - /// - /// Handles the specified request. - /// - /// The request. - /// The cancellation token. - /// - /// Response from the request - /// - public async Task Handle(ProcessReconciliationRequest request, - CancellationToken cancellationToken) - { - return await this.ApplicationService.ProcessReconciliation(request.EstateId, - request.MerchantId, - request.TransactionDateTime, - request.DeviceIdentifier, - request.TransactionCount, - request.TransactionValue, - cancellationToken); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessSaleTransactionRequestHandler.cs b/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessSaleTransactionRequestHandler.cs deleted file mode 100644 index eacd6b8..0000000 --- a/TransactionProcessorACL.BusinessLogic/RequestHandlers/ProcessSaleTransactionRequestHandler.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace TransactionProcessorACL.BusinessLogic.RequestHandlers -{ - using System.Threading; - using System.Threading.Tasks; - using MediatR; - using Models; - using Requests; - using Services; - - public class ProcessSaleTransactionRequestHandler : IRequestHandler - { - #region Fields - - /// - /// The application service - /// - private readonly ITransactionProcessorACLApplicationService ApplicationService; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The application service. - public ProcessSaleTransactionRequestHandler(ITransactionProcessorACLApplicationService applicationService) - { - this.ApplicationService = applicationService; - } - - #endregion - - #region Methods - - /// - /// Handles the specified request. - /// - /// The request. - /// The cancellation token. - /// - /// Response from the request - /// - public async Task Handle(ProcessSaleTransactionRequest request, - CancellationToken cancellationToken) - { - return await this.ApplicationService.ProcessSaleTransaction(request.EstateId, - request.MerchantId, - request.TransactionDateTime, - request.TransactionNumber, - request.DeviceIdentifier, - request.OperatorId, - request.CustomerEmailAddress, - request.ContractId, - request.ProductId, - request.AdditionalRequestMetadata, - cancellationToken); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/RequestHandlers/VersionCheckRequestHandler.cs b/TransactionProcessorACL.BusinessLogic/RequestHandlers/VersionCheckRequestHandler.cs index 26cbd02..6f7669c 100644 --- a/TransactionProcessorACL.BusinessLogic/RequestHandlers/VersionCheckRequestHandler.cs +++ b/TransactionProcessorACL.BusinessLogic/RequestHandlers/VersionCheckRequestHandler.cs @@ -1,4 +1,6 @@ -namespace TransactionProcessorACL.BusinessLogic.RequestHandlers +using SimpleResults; + +namespace TransactionProcessorACL.BusinessLogic.RequestHandlers { using System; using System.Net; @@ -18,22 +20,15 @@ /// /// /// - public class VersionCheckRequestHandler : IRequestHandler + public class VersionCheckRequestHandler : IRequestHandler { #region Methods - /// - /// Handles the specified request. - /// - /// The request. - /// The cancellation token. - /// - /// Version number [{requestVersion}] is less than the Minimum Supported version [{minimumVersion}] - public async Task Handle(VersionCheckRequest request, - CancellationToken cancellationToken) { + public async Task Handle(VersionCheckCommands.VersionCheckCommand command, + CancellationToken cancellationToken) { if (Environment.GetEnvironmentVariable("AppSettings:SkipVersionCheck") != null) { if (Boolean.TryParse(ConfigurationReader.GetValue("AppSettings","SkipVersionCheck"), out Boolean skipVersionCheck) && skipVersionCheck) { - return; + return Result.Success(); } } @@ -43,13 +38,15 @@ public async Task Handle(VersionCheckRequest request, // Convert to an assembly version Version minimumVersion = Version.Parse(versionFromConfig); - Version.TryParse(request.VersionNumber, out Version requestVersion); + Version.TryParse(command.VersionNumber, out Version requestVersion); if (requestVersion == null || requestVersion.CompareTo(minimumVersion) < 0) { // This is not compatible - throw new VersionIncompatibleException($"Version Mistmatch - Version number [{requestVersion}] is less than the Minimum Supported version [{minimumVersion}]"); + return Result.Conflict( + $"Version Mistmatch - Version number [{requestVersion}] is less than the Minimum Supported version [{minimumVersion}]"); } + return Result.Success(); } #endregion diff --git a/TransactionProcessorACL.BusinessLogic/RequestHandlers/VoucherRequestHandler.cs b/TransactionProcessorACL.BusinessLogic/RequestHandlers/VoucherRequestHandler.cs index 019dff6..c3957c9 100644 --- a/TransactionProcessorACL.BusinessLogic/RequestHandlers/VoucherRequestHandler.cs +++ b/TransactionProcessorACL.BusinessLogic/RequestHandlers/VoucherRequestHandler.cs @@ -5,15 +5,16 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using SimpleResults; using TransactionProcessorACL.BusinessLogic.Requests; namespace TransactionProcessorACL.BusinessLogic.RequestHandlers { using Models; using Services; - using RedeemVoucherRequest = Requests.RedeemVoucherRequest; - public class VoucherRequestHandler : IRequestHandler, IRequestHandler + public class VoucherRequestHandler : IRequestHandler>, + IRequestHandler> { #region Fields @@ -36,31 +37,15 @@ public VoucherRequestHandler(ITransactionProcessorACLApplicationService applicat #region Methods - /// - /// Handles a request - /// - /// The request - /// Cancellation token - /// - /// Response from the request - /// - public async Task Handle(GetVoucherRequest request, - CancellationToken cancellationToken) + public async Task> Handle(VoucherQueries.GetVoucherQuery query, + CancellationToken cancellationToken) { - return await this.ApplicationService.GetVoucher(request.EstateId, request.ContractId, request.VoucherCode, cancellationToken); + return await this.ApplicationService.GetVoucher(query.EstateId, query.ContractId, query.VoucherCode, cancellationToken); } - /// - /// Handles a request - /// - /// The request - /// Cancellation token - /// - /// Response from the request - /// - public async Task Handle(RedeemVoucherRequest request, - CancellationToken cancellationToken){ - return await this.ApplicationService.RedeemVoucher(request.EstateId, request.ContractId, request.VoucherCode, cancellationToken); + public async Task> Handle(VoucherCommands.RedeemVoucherCommand command, + CancellationToken cancellationToken){ + return await this.ApplicationService.RedeemVoucher(command.EstateId, command.ContractId, command.VoucherCode, cancellationToken); } #endregion diff --git a/TransactionProcessorACL.BusinessLogic/Requests/GetVoucherRequest.cs b/TransactionProcessorACL.BusinessLogic/Requests/GetVoucherRequest.cs deleted file mode 100644 index d2ef9e0..0000000 --- a/TransactionProcessorACL.BusinessLogic/Requests/GetVoucherRequest.cs +++ /dev/null @@ -1,142 +0,0 @@ -using MediatR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TransactionProcessorACL.BusinessLogic.Requests -{ - using Models; - - public class GetVoucherRequest : IRequest - { - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The estate identifier. - /// The contract identifier. - /// The voucher code. - private GetVoucherRequest(Guid estateId, - Guid contractId, - String voucherCode) - { - this.EstateId = estateId; - this.ContractId = contractId; - this.VoucherCode = voucherCode; - } - - #endregion - - #region Properties - - /// - /// Gets the contract identifier. - /// - /// - /// The contract identifier. - /// - public Guid ContractId { get; } - - /// - /// Gets the estate identifier. - /// - /// - /// The estate identifier. - /// - public Guid EstateId { get; } - - /// - /// Gets the voucher code. - /// - /// - /// The voucher code. - /// - public String VoucherCode { get; } - - #endregion - - #region Methods - - /// - /// Creates the specified version number. - /// - /// The estate identifier. - /// The contract identifier. - /// The voucher code. - /// - public static GetVoucherRequest Create(Guid estateId, - Guid contractId, - String voucherCode) - { - return new GetVoucherRequest(estateId, contractId, voucherCode); - } - - #endregion - } - - public class RedeemVoucherRequest : IRequest - { - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The estate identifier. - /// The contract identifier. - /// The voucher code. - private RedeemVoucherRequest(Guid estateId, Guid contractId, String voucherCode) - { - this.EstateId = estateId; - this.ContractId = contractId; - this.VoucherCode = voucherCode; - } - - #endregion - - #region Properties - - /// - /// Gets the estate identifier. - /// - /// - /// The estate identifier. - /// - public Guid EstateId { get; } - - /// - /// Gets the contract identifier. - /// - /// - /// The contract identifier. - /// - public Guid ContractId { get; } - /// - /// Gets the voucher code. - /// - /// - /// The voucher code. - /// - public String VoucherCode { get; } - - #endregion - - #region Methods - - /// - /// Creates the specified version number. - /// - /// The estate identifier. - /// The contract identifier. - /// The voucher code. - /// - public static RedeemVoucherRequest Create(Guid estateId, Guid contractId, String voucherCode) - { - return new RedeemVoucherRequest(estateId, contractId, voucherCode); - } - - #endregion - } -} diff --git a/TransactionProcessorACL.BusinessLogic/Requests/ProcessLogonTransactionRequest.cs b/TransactionProcessorACL.BusinessLogic/Requests/ProcessLogonTransactionRequest.cs deleted file mode 100644 index 526410c..0000000 --- a/TransactionProcessorACL.BusinessLogic/Requests/ProcessLogonTransactionRequest.cs +++ /dev/null @@ -1,112 +0,0 @@ -namespace TransactionProcessorACL.BusinessLogic.Requests -{ - using System; - using System.Diagnostics.CodeAnalysis; - using MediatR; - using Models; - - /// - /// - /// - /// - public class ProcessLogonTransactionRequest : IRequest - { - #region Constructors - - [ExcludeFromCodeCoverage] - public ProcessLogonTransactionRequest() - { - - } - - /// - /// Initializes a new instance of the class. - /// - /// The estate identifier. - /// The merchant identifier. - /// The transaction date time. - /// The transaction number. - /// The device identifier. - /// if set to true [require configuration in response]. - private ProcessLogonTransactionRequest(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String transactionNumber, - String deviceIdentifier) - { - this.EstateId = estateId; - this.MerchantId = merchantId; - this.DeviceIdentifier = deviceIdentifier; - this.TransactionDateTime = transactionDateTime; - this.TransactionNumber = transactionNumber; - } - - #endregion - - #region Properties - - /// - /// Gets the estate identifier. - /// - /// - /// The estate identifier. - /// - public Guid EstateId { get; } - - /// - /// Gets the device identifier. - /// - /// - /// The device identifier. - /// - public String DeviceIdentifier { get; } - - /// - /// Gets the merchant identifier. - /// - /// - /// The merchant identifier. - /// - public Guid MerchantId { get; } - - /// - /// Gets the transaction date time. - /// - /// - /// The transaction date time. - /// - public DateTime TransactionDateTime { get; } - - /// - /// Gets the transaction number. - /// - /// - /// The transaction number. - /// - public String TransactionNumber { get; } - - #endregion - - #region Methods - - /// - /// Creates the specified estate identifier. - /// - /// The estate identifier. - /// The merchant identifier. - /// The transaction date time. - /// The transaction number. - /// The device identifier. - /// - public static ProcessLogonTransactionRequest Create(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String transactionNumber, - String deviceIdentifier) - { - return new ProcessLogonTransactionRequest(estateId, merchantId, transactionDateTime, transactionNumber, deviceIdentifier); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Requests/ProcessReconciliationRequest.cs b/TransactionProcessorACL.BusinessLogic/Requests/ProcessReconciliationRequest.cs deleted file mode 100644 index 97af816..0000000 --- a/TransactionProcessorACL.BusinessLogic/Requests/ProcessReconciliationRequest.cs +++ /dev/null @@ -1,127 +0,0 @@ -namespace TransactionProcessorACL.BusinessLogic.Requests -{ - using System; - using System.Diagnostics.CodeAnalysis; - using MediatR; - using Models; - - /// - /// - /// - /// - /// - public class ProcessReconciliationRequest : IRequest - { - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public ProcessReconciliationRequest() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The estate identifier. - /// The merchant identifier. - /// The transaction date time. - /// The device identifier. - /// The transaction count. - /// The transaction value. - private ProcessReconciliationRequest(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String deviceIdentifier, - Int32 transactionCount, - Decimal transactionValue) - { - this.EstateId = estateId; - this.MerchantId = merchantId; - this.DeviceIdentifier = deviceIdentifier; - this.TransactionCount = transactionCount; - this.TransactionValue = transactionValue; - this.TransactionDateTime = transactionDateTime; - } - - #endregion - - #region Properties - - /// - /// Gets the device identifier. - /// - /// - /// The device identifier. - /// - public String DeviceIdentifier { get; } - - /// - /// Gets the estate identifier. - /// - /// - /// The estate identifier. - /// - public Guid EstateId { get; } - - /// - /// Gets the merchant identifier. - /// - /// - /// The merchant identifier. - /// - public Guid MerchantId { get; } - - /// - /// Gets the transaction count. - /// - /// - /// The transaction count. - /// - public Int32 TransactionCount { get; } - - /// - /// Gets the transaction date time. - /// - /// - /// The transaction date time. - /// - public DateTime TransactionDateTime { get; } - - /// - /// Gets the transaction value. - /// - /// - /// The transaction value. - /// - public Decimal TransactionValue { get; } - - #endregion - - #region Methods - - /// - /// Creates the specified estate identifier. - /// - /// The estate identifier. - /// The merchant identifier. - /// The transaction date time. - /// The device identifier. - /// The transaction count. - /// The transaction value. - /// - public static ProcessReconciliationRequest Create(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String deviceIdentifier, - Int32 transactionCount, - Decimal transactionValue) - { - return new ProcessReconciliationRequest(estateId, merchantId, transactionDateTime, deviceIdentifier, transactionCount, transactionValue); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Requests/ProcessSaleTransactionRequest.cs b/TransactionProcessorACL.BusinessLogic/Requests/ProcessSaleTransactionRequest.cs deleted file mode 100644 index 2a5ea67..0000000 --- a/TransactionProcessorACL.BusinessLogic/Requests/ProcessSaleTransactionRequest.cs +++ /dev/null @@ -1,185 +0,0 @@ -namespace TransactionProcessorACL.BusinessLogic.Requests -{ - using System; - using System.Collections.Generic; - using System.Diagnostics.CodeAnalysis; - using MediatR; - using Models; - - public class ProcessSaleTransactionRequest : IRequest - { - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public ProcessSaleTransactionRequest() - { - - } - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The estate identifier. - /// The merchant identifier. - /// The transaction date time. - /// The transaction number. - /// The device identifier. - /// The operator identifier. - /// The customer email address. - /// The contract identifier. - /// The product identifier. - /// The additional request metadata. - private ProcessSaleTransactionRequest(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String transactionNumber, - String deviceIdentifier, - Guid operatorId, - String customerEmailAddress, - Guid contractId, - Guid productId, - Dictionary additionalRequestMetadata) - { - this.EstateId = estateId; - this.MerchantId = merchantId; - this.DeviceIdentifier = deviceIdentifier; - this.OperatorId = operatorId; - this.CustomerEmailAddress = customerEmailAddress; - this.ContractId = contractId; - this.ProductId = productId; - this.AdditionalRequestMetadata = additionalRequestMetadata; - this.TransactionDateTime = transactionDateTime; - this.TransactionNumber = transactionNumber; - } - - #endregion - - #region Properties - - /// - /// Gets the customer email address. - /// - /// - /// The customer email address. - /// - public String CustomerEmailAddress { get; private set; } - - /// - /// Gets the contract identifier. - /// - /// - /// The contract identifier. - /// - public Guid ContractId { get; } - - /// - /// Gets the product identifier. - /// - /// - /// The product identifier. - /// - public Guid ProductId { get; } - - /// - /// Gets the additional request metadata. - /// - /// - /// The additional request metadata. - /// - public Dictionary AdditionalRequestMetadata { get; } - - /// - /// Gets the device identifier. - /// - /// - /// The device identifier. - /// - public String DeviceIdentifier { get; } - - /// - /// Gets the estate identifier. - /// - /// - /// The estate identifier. - /// - public Guid EstateId { get; } - - /// - /// Gets the merchant identifier. - /// - /// - /// The merchant identifier. - /// - public Guid MerchantId { get; } - - /// - /// Gets the operator identifier. - /// - /// - /// The operator identifier. - /// - public Guid OperatorId { get; } - - /// - /// Gets the transaction date time. - /// - /// - /// The transaction date time. - /// - public DateTime TransactionDateTime { get; } - - /// - /// Gets the transaction number. - /// - /// - /// The transaction number. - /// - public String TransactionNumber { get; } - - #endregion - - #region Methods - - /// - /// Creates the specified estate identifier. - /// - /// The estate identifier. - /// The merchant identifier. - /// The transaction date time. - /// The transaction number. - /// The device identifier. - /// The operator identifier. - /// The customer email address. - /// The contract identifier. - /// The product identifier. - /// The additional request metadata. - /// - public static ProcessSaleTransactionRequest Create(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String transactionNumber, - String deviceIdentifier, - Guid operatorId, - String customerEmailAddress, - Guid contractId, - Guid productId, - Dictionary additionalRequestMetadata) - { - return new ProcessSaleTransactionRequest(estateId, - merchantId, - transactionDateTime, - transactionNumber, - deviceIdentifier, - operatorId, - customerEmailAddress, - contractId, - productId, - additionalRequestMetadata); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs b/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs new file mode 100644 index 0000000..831c93f --- /dev/null +++ b/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using MediatR; +using SimpleResults; +using TransactionProcessorACL.Models; + +namespace TransactionProcessorACL.BusinessLogic.Requests; + +public record TransactionCommands { + public record ProcessLogonTransactionCommand(Guid EstateId, + Guid MerchantId, + DateTime TransactionDateTime, + String TransactionNumber, + String DeviceIdentifier) + : IRequest>; + + public record ProcessSaleTransactionCommand(Guid EstateId, + Guid MerchantId, + DateTime TransactionDateTime, + String TransactionNumber, + String DeviceIdentifier, + Guid OperatorId, + String CustomerEmailAddress, + Guid ContractId, + Guid ProductId, + Dictionary AdditionalRequestMetadata) + : IRequest>; + + public record ProcessReconciliationCommand(Guid EstateId, + Guid MerchantId, + DateTime TransactionDateTime, + String DeviceIdentifier, + Int32 TransactionCount, + Decimal TransactionValue) + : IRequest>; +} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Requests/VersionCheckCommands.cs b/TransactionProcessorACL.BusinessLogic/Requests/VersionCheckCommands.cs new file mode 100644 index 0000000..a8cf06f --- /dev/null +++ b/TransactionProcessorACL.BusinessLogic/Requests/VersionCheckCommands.cs @@ -0,0 +1,9 @@ +using System; +using MediatR; +using SimpleResults; + +namespace TransactionProcessorACL.BusinessLogic.Requests; + +public record VersionCheckCommands { + public record VersionCheckCommand(String VersionNumber) : IRequest; +} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Requests/VersionCheckRequest.cs b/TransactionProcessorACL.BusinessLogic/Requests/VersionCheckRequest.cs deleted file mode 100644 index d70a77e..0000000 --- a/TransactionProcessorACL.BusinessLogic/Requests/VersionCheckRequest.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace TransactionProcessorACL.BusinessLogic.Requests -{ - using System; - using MediatR; - - /// - /// - /// - /// - public class VersionCheckRequest : IRequest - { - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The version number. - private VersionCheckRequest(String versionNumber) - { - this.VersionNumber = versionNumber; - } - - #endregion - - #region Properties - - /// - /// Gets the version number. - /// - /// - /// The version number. - /// - public String VersionNumber { get; } - - #endregion - - #region Methods - - /// - /// Creates the specified version number. - /// - /// The version number. - /// - public static VersionCheckRequest Create(String versionNumber) - { - return new VersionCheckRequest(versionNumber); - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Requests/VoucherCommands.cs b/TransactionProcessorACL.BusinessLogic/Requests/VoucherCommands.cs new file mode 100644 index 0000000..34d55f7 --- /dev/null +++ b/TransactionProcessorACL.BusinessLogic/Requests/VoucherCommands.cs @@ -0,0 +1,10 @@ +using System; +using MediatR; +using SimpleResults; +using TransactionProcessorACL.Models; + +namespace TransactionProcessorACL.BusinessLogic.Requests; + +public record VoucherCommands { + public record RedeemVoucherCommand(Guid EstateId, Guid ContractId, String VoucherCode) : IRequest>; +} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Requests/VoucherQueries.cs b/TransactionProcessorACL.BusinessLogic/Requests/VoucherQueries.cs new file mode 100644 index 0000000..8ec566a --- /dev/null +++ b/TransactionProcessorACL.BusinessLogic/Requests/VoucherQueries.cs @@ -0,0 +1,11 @@ +using System; +using MediatR; +using SimpleResults; +using TransactionProcessorACL.Models; + +namespace TransactionProcessorACL.BusinessLogic.Requests; + +public record VoucherQueries { + public record GetVoucherQuery(Guid EstateId, Guid ContractId, String VoucherCode) + : IRequest>; +} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs index 3a821b1..b4062c5 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using SimpleResults; namespace TransactionProcessorACL.BusinessLogic.Services { @@ -14,14 +15,14 @@ namespace TransactionProcessorACL.BusinessLogic.Services public interface ITransactionProcessorACLApplicationService { - Task ProcessLogonTransaction(Guid estateId, + Task> ProcessLogonTransaction(Guid estateId, Guid merchantId, DateTime transactionDateTime, String transactionNumber, String deviceIdentifier, CancellationToken cancellationToken); - Task ProcessSaleTransaction(Guid estateId, + Task> ProcessSaleTransaction(Guid estateId, Guid merchantId, DateTime transactionDateTime, String transactionNumber, @@ -33,7 +34,7 @@ Task ProcessSaleTransaction(Guid estateId, Dictionary additionalRequestMetadata, CancellationToken cancellationToken); - Task ProcessReconciliation(Guid estateId, + Task> ProcessReconciliation(Guid estateId, Guid merchantId, DateTime transactionDateTime, String deviceIdentifier, diff --git a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs index 57dedec..61ea6a5 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs @@ -1,4 +1,6 @@ -namespace TransactionProcessorACL.BusinessLogic.Services +using SimpleResults; + +namespace TransactionProcessorACL.BusinessLogic.Services { using System; using System.Collections.Generic; @@ -64,12 +66,12 @@ public TransactionProcessorACLApplicationService(ITransactionProcessorClient tra /// The device identifier. /// The cancellation token. /// - public async Task ProcessLogonTransaction(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String transactionNumber, - String deviceIdentifier, - CancellationToken cancellationToken) + public async Task> ProcessLogonTransaction(Guid estateId, + Guid merchantId, + DateTime transactionDateTime, + String transactionNumber, + String deviceIdentifier, + CancellationToken cancellationToken) { // Get a client token to call the Transaction Processor String clientId = ConfigurationReader.GetValue("AppSettings", "ClientId"); @@ -148,7 +150,7 @@ public async Task ProcessLogonTransaction(Guid } } - return response; + return Result.Success(response); } /// @@ -166,17 +168,17 @@ public async Task ProcessLogonTransaction(Guid /// The additional request metadata. /// The cancellation token. /// - public async Task ProcessSaleTransaction(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String transactionNumber, - String deviceIdentifier, - Guid operatorId, - String customerEmailAddress, - Guid contractId, - Guid productId, - Dictionary additionalRequestMetadata, - CancellationToken cancellationToken) + public async Task> ProcessSaleTransaction(Guid estateId, + Guid merchantId, + DateTime transactionDateTime, + String transactionNumber, + String deviceIdentifier, + Guid operatorId, + String customerEmailAddress, + Guid contractId, + Guid productId, + Dictionary additionalRequestMetadata, + CancellationToken cancellationToken) { // Get a client token to call the Transaction Processor String clientId = ConfigurationReader.GetValue("AppSettings", "ClientId"); @@ -264,16 +266,16 @@ public async Task ProcessSaleTransaction(Guid es } } - return response; + return Result.Success(response); } - public async Task ProcessReconciliation(Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String deviceIdentifier, - Int32 transactionCount, - Decimal transactionValue, - CancellationToken cancellationToken) + public async Task> ProcessReconciliation(Guid estateId, + Guid merchantId, + DateTime transactionDateTime, + String deviceIdentifier, + Int32 transactionCount, + Decimal transactionValue, + CancellationToken cancellationToken) { // Get a client token to call the Transaction Processor String clientId = ConfigurationReader.GetValue("AppSettings", "ClientId"); @@ -342,7 +344,7 @@ public async Task ProcessReconciliation(Guid esta } } - return response; + return Result.Success(response); } public async Task GetVoucher(Guid estateId, diff --git a/TransactionProcessorACL.BusinessLogic/TransactionProcessorACL.BusinessLogic.csproj b/TransactionProcessorACL.BusinessLogic/TransactionProcessorACL.BusinessLogic.csproj index 8e6d005..16749fc 100644 --- a/TransactionProcessorACL.BusinessLogic/TransactionProcessorACL.BusinessLogic.csproj +++ b/TransactionProcessorACL.BusinessLogic/TransactionProcessorACL.BusinessLogic.csproj @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/TransactionProcessorACL.IntegrationTests/Common/DockerHelper.cs b/TransactionProcessorACL.IntegrationTests/Common/DockerHelper.cs index 8dcd762..6ad3e39 100644 --- a/TransactionProcessorACL.IntegrationTests/Common/DockerHelper.cs +++ b/TransactionProcessorACL.IntegrationTests/Common/DockerHelper.cs @@ -109,7 +109,7 @@ public override async Task StartContainersForScenarioRun(String scenarioName, Do }; HttpClient httpClient = new HttpClient(clientHandler); - this.EstateClient = new EstateClient(EstateManagementBaseAddressResolver, httpClient); + this.EstateClient = new EstateClient(EstateManagementBaseAddressResolver, httpClient, 2); this.SecurityServiceClient = new SecurityServiceClient(SecurityServiceBaseAddressResolver, httpClient); this.TransactionProcessorClient = new TransactionProcessorClient(TransactionProcessorBaseAddressResolver, httpClient); this.TestHostHttpClient = new HttpClient(clientHandler); diff --git a/TransactionProcessorACL.IntegrationTests/Shared/ACLSteps.cs b/TransactionProcessorACL.IntegrationTests/Shared/ACLSteps.cs index 6b92263..1f32a90 100644 --- a/TransactionProcessorACL.IntegrationTests/Shared/ACLSteps.cs +++ b/TransactionProcessorACL.IntegrationTests/Shared/ACLSteps.cs @@ -27,6 +27,11 @@ public ACLSteps(HttpClient httpClient, ITransactionProcessorClient transactionPr this.TransactionProcessorClient = transactionProcessorClient; } + internal class ResponseData + { + public T Data { get; set; } + } + public async Task SendAclRequestMessage((EstateDetails, String, Guid, String, TransactionRequestMessage) requestMessage, CancellationToken cancellationToken){ String uri = "api/transactions"; @@ -47,8 +52,13 @@ public async Task SendAclRequestMessage((EstateDetails, String, Guid, String, Tr String responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); responseContent.ShouldNotBeNullOrEmpty("No response message received"); + + ResponseData responseData = + JsonConvert.DeserializeObject>(responseContent); + + String responseMessage = JsonConvert.SerializeObject(responseData.Data); - requestMessage.Item1.AddTransactionResponse(requestMessage.Item3, requestMessage.Item4, responseContent); + requestMessage.Item1.AddTransactionResponse(requestMessage.Item3, requestMessage.Item4, responseMessage); } public void ThenTheLogonTransactionResponseShouldContainTheFollowingInformation(List expectedResponses, List estateDetailsList) diff --git a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs index 4d546de..907527d 100644 --- a/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs +++ b/TransactionProcessorACL.IntegrationTests/Shared/SharedSteps.cs @@ -138,6 +138,11 @@ public async Task GivenICreateAContractWithTheFollowingValues(DataTable table){ var estates = this.TestingContext.Estates.Select(e => e.EstateDetails).ToList(); List<(EstateDetails, CreateContractRequest)> requests = table.Rows.ToCreateContractRequests(estates); List responses = await this.EstateManagementSteps.GivenICreateAContractWithTheFollowingValues(this.TestingContext.AccessToken, requests); + foreach (ContractResponse contractResponse in responses) + { + var estate = this.TestingContext.Estates.Single(e => e.EstateDetails.EstateId == contractResponse.EstateId); + estate.EstateDetails.AddContract(contractResponse.ContractId, contractResponse.Description, contractResponse.OperatorId); + } } [Given(@"I create the following api scopes")] diff --git a/TransactionProcessorACL.IntegrationTests/TransactionProcessorACL.IntegrationTests.csproj b/TransactionProcessorACL.IntegrationTests/TransactionProcessorACL.IntegrationTests.csproj index fc4d5e2..978777f 100644 --- a/TransactionProcessorACL.IntegrationTests/TransactionProcessorACL.IntegrationTests.csproj +++ b/TransactionProcessorACL.IntegrationTests/TransactionProcessorACL.IntegrationTests.csproj @@ -7,11 +7,11 @@ - + - - - + + + @@ -24,10 +24,10 @@ - + - - + + all diff --git a/TransactionProcessorACL.Testing/TestData.cs b/TransactionProcessorACL.Testing/TestData.cs index bea52d0..8ef0ba1 100644 --- a/TransactionProcessorACL.Testing/TestData.cs +++ b/TransactionProcessorACL.Testing/TestData.cs @@ -10,7 +10,6 @@ using TransactionProcessorACL.BusinessLogic.Requests; using TransactionProcessorACL.DataTransferObjects; using GetVoucherResponse = TransactionProcessor.DataTransferObjects.GetVoucherResponse; - using RedeemVoucherRequest = BusinessLogic.Requests.RedeemVoucherRequest; using RedeemVoucherResponse = TransactionProcessor.DataTransferObjects.RedeemVoucherResponse; /// @@ -58,8 +57,8 @@ public class TestData /// /// The process logon transaction request /// - public static ProcessLogonTransactionRequest ProcessLogonTransactionRequest = - ProcessLogonTransactionRequest.Create(TestData.EstateId, + public static TransactionCommands.ProcessLogonTransactionCommand ProcessLogonTransactionCommand = + new(TestData.EstateId, TestData.MerchantId, TestData.TransactionDateTime, TestData.TransactionNumber, @@ -158,7 +157,7 @@ public class TestData {"CustomerAccountNumber", TestData.CustomerAccountNumber} }; - public static ProcessSaleTransactionRequest ProcessSaleTransactionRequest = ProcessSaleTransactionRequest.Create(TestData.EstateId, + public static TransactionCommands.ProcessSaleTransactionCommand ProcessSaleTransactionCommand = new(TestData.EstateId, TestData.MerchantId, TestData.TransactionDateTime, TestData.TransactionNumber, @@ -173,7 +172,7 @@ public class TestData public static Decimal ReconciliationTransactionValue = 100.00m; - public static ProcessReconciliationRequest ProcessReconciliationRequest= ProcessReconciliationRequest.Create(TestData.EstateId, + public static TransactionCommands.ProcessReconciliationCommand ProcessReconciliationCommand = new(TestData.EstateId, TestData.MerchantId, TestData.TransactionDateTime, TestData.DeviceIdentifier, @@ -225,9 +224,9 @@ public class TestData public static String NewerApplicationVersion = "1.0.5.1"; public static String ApplicationVersion = "1.0.5"; - public static VersionCheckRequest VersionCheckRequest = VersionCheckRequest.Create(TestData.ApplicationVersion); - public static RedeemVoucherRequest RedeemVoucherRequest = RedeemVoucherRequest.Create(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); - public static GetVoucherRequest GetVoucherRequest = GetVoucherRequest.Create(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); + public static VersionCheckCommands.VersionCheckCommand VersionCheckCommand = new(TestData.ApplicationVersion); + public static VoucherCommands.RedeemVoucherCommand RedeemVoucherCommand => new(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); + public static VoucherQueries.GetVoucherQuery GetVoucherQuery => new(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); public static String VoucherCode = "1231231234"; public static DateTime ExpiryDate = new DateTime(2021, 1, 11); diff --git a/TransactionProcessorACL.Testing/TransactionProcessorACL.Testing.csproj b/TransactionProcessorACL.Testing/TransactionProcessorACL.Testing.csproj index fa1a40e..7632fea 100644 --- a/TransactionProcessorACL.Testing/TransactionProcessorACL.Testing.csproj +++ b/TransactionProcessorACL.Testing/TransactionProcessorACL.Testing.csproj @@ -6,9 +6,9 @@ - - - + + + diff --git a/TransactionProcessorACL.Tests/Common/TransactionProcessorACLWebFactory.cs b/TransactionProcessorACL.Tests/Common/TransactionProcessorACLWebFactory.cs index b8f94f9..6097383 100644 --- a/TransactionProcessorACL.Tests/Common/TransactionProcessorACLWebFactory.cs +++ b/TransactionProcessorACL.Tests/Common/TransactionProcessorACLWebFactory.cs @@ -47,7 +47,7 @@ private Mock CreateMediatorMock() { Mock mediatorMock = new Mock(MockBehavior.Strict); - mediatorMock.Setup(c => c.Send(It.IsAny(), It.IsAny())).ReturnsAsync(new ProcessLogonTransactionResponse + mediatorMock.Setup(c => c.Send(It.IsAny(), It.IsAny())).ReturnsAsync(new ProcessLogonTransactionResponse { ResponseCode = "0000", ResponseMessage = "SUCCESS" diff --git a/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs b/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs index 683ed5f..20cb01d 100644 --- a/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs +++ b/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs @@ -1,4 +1,6 @@ -namespace TransactionProcessorACL.Bootstrapper +using SimpleResults; + +namespace TransactionProcessorACL.Bootstrapper { using BusinessLogic.RequestHandlers; using BusinessLogic.Requests; @@ -7,8 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using Models; using System.Diagnostics.CodeAnalysis; - using RedeemVoucherRequest = BusinessLogic.Requests.RedeemVoucherRequest; - + /// /// /// @@ -25,17 +26,14 @@ public MediatorRegistry() { this.AddTransient(); - this.AddSingleton, VersionCheckRequestHandler>(); + this.AddSingleton, VersionCheckRequestHandler>(); - this.AddSingleton, ProcessLogonTransactionRequestHandler>(); - this.AddSingleton, ProcessSaleTransactionRequestHandler>(); - this.AddSingleton, ProcessReconciliationRequestHandler>(); - this.AddSingleton, ProcessLogonTransactionRequest>(); - this.AddSingleton, ProcessSaleTransactionRequest>(); - this.AddSingleton, ProcessReconciliationRequest>(); - - this.AddSingleton, VoucherRequestHandler>(); - this.AddSingleton, VoucherRequestHandler>(); + this.AddSingleton>, TransactionRequestHandler>(); + this.AddSingleton>, TransactionRequestHandler>(); + this.AddSingleton>, TransactionRequestHandler>(); + + this.AddSingleton>, VoucherRequestHandler>(); + this.AddSingleton>, VoucherRequestHandler>(); } #endregion diff --git a/TransactionProcessorACL/Controllers/ResultExtensions.cs b/TransactionProcessorACL/Controllers/ResultExtensions.cs new file mode 100644 index 0000000..1573d93 --- /dev/null +++ b/TransactionProcessorACL/Controllers/ResultExtensions.cs @@ -0,0 +1,63 @@ +using System; +using System.Net; +using Microsoft.AspNetCore.Mvc; +using SimpleResults; + +namespace TransactionProcessorACL.Controllers; + +public static class ResultExtensions +{ + public static IActionResult ToActionResultX(this Result result) + { + if (result.IsSuccess) + return new OkObjectResult(result); + + return result.Status switch + { + ResultStatus.Invalid => new BadRequestObjectResult(result), + ResultStatus.NotFound => new NotFoundObjectResult(result), + ResultStatus.Unauthorized => new UnauthorizedObjectResult(result), + ResultStatus.Conflict => new ConflictObjectResult(result), + ResultStatus.Failure => CreateObjectResult(result, HttpStatusCode.InternalServerError), + ResultStatus.CriticalError => CreateObjectResult(result, HttpStatusCode.InternalServerError), + ResultStatus.Forbidden => new ForbidResult(), + _ => CreateObjectResult(result, HttpStatusCode.NotImplemented) + + }; + } + + internal static IActionResult ToActionResultX(this Result result) + { + if (result.IsSuccess) + return new OkObjectResult(result); + + return result.Status switch + { + ResultStatus.Invalid => new BadRequestObjectResult(result), + ResultStatus.NotFound => new NotFoundObjectResult(result), + ResultStatus.Unauthorized => new UnauthorizedObjectResult(result), + ResultStatus.Conflict => new ConflictObjectResult(result), + ResultStatus.Failure => CreateObjectResult(result, HttpStatusCode.InternalServerError), + ResultStatus.CriticalError => CreateObjectResult(result, HttpStatusCode.InternalServerError), + ResultStatus.Forbidden => new ForbidResult(), + _ => CreateObjectResult(result, HttpStatusCode.NotImplemented) + + }; + } + + internal static ObjectResult CreateObjectResult(Result result, + HttpStatusCode statusCode) + { + ObjectResult or = new ObjectResult(result); + or.StatusCode = (Int32)statusCode; + return or; + } + + internal static ObjectResult CreateObjectResult(Result result, + HttpStatusCode statusCode) + { + ObjectResult or = new ObjectResult(result); + or.StatusCode = (Int32)statusCode; + return or; + } +} \ No newline at end of file diff --git a/TransactionProcessorACL/Controllers/TransactionController.cs b/TransactionProcessorACL/Controllers/TransactionController.cs index d4ad86b..79d2b52 100644 --- a/TransactionProcessorACL/Controllers/TransactionController.cs +++ b/TransactionProcessorACL/Controllers/TransactionController.cs @@ -1,4 +1,6 @@ -namespace TransactionProcessorACL.Controllers +using SimpleResults; + +namespace TransactionProcessorACL.Controllers { using System; using System.Diagnostics.CodeAnalysis; @@ -19,6 +21,7 @@ using Shared.Logger; using Swashbuckle.AspNetCore.Annotations; using Swashbuckle.AspNetCore.Filters; + using static TransactionProcessorACL.BusinessLogic.Requests.VersionCheckCommands; /// /// @@ -83,38 +86,40 @@ public async Task PerformTransaction([FromBody] TransactionReques } // Do the software version check - try - { - VersionCheckRequest versionCheckRequest = VersionCheckRequest.Create(transactionRequest.ApplicationVersion); - await this.Mediator.Send(versionCheckRequest, cancellationToken); - } - catch(VersionIncompatibleException vex) - { - Logger.LogError(vex); + VersionCheckCommand versionCheckCommand = new(transactionRequest.ApplicationVersion); + var versionCheckResult = await this.Mediator.Send(versionCheckCommand, cancellationToken); + if (versionCheckResult.IsFailed) return this.StatusCode(505); - } // Now do the transaction TransactionResponseMessage dto = null; switch (transactionRequest){ case SaleTransactionRequestMessage msg: - ProcessSaleTransactionRequest saleRequest = this.CreateCommandFromRequest(msg); - ProcessSaleTransactionResponse saleResponse = await this.Mediator.Send(saleRequest, cancellationToken); + TransactionCommands.ProcessSaleTransactionCommand saleCommand = this.CreateCommandFromRequest(msg); + Result saleResponse = await this.Mediator.Send(saleCommand, cancellationToken); + // TODO: Handle the result + if (saleResponse.IsFailed) + return saleResponse.ToActionResultX(); dto = this.ModelFactory.ConvertFrom(saleResponse); break; case LogonTransactionRequestMessage msg: - ProcessLogonTransactionRequest logonRequest = this.CreateCommandFromRequest(msg); - ProcessLogonTransactionResponse logonResponse = await this.Mediator.Send(logonRequest, cancellationToken); + TransactionCommands.ProcessLogonTransactionCommand logonCommand= this.CreateCommandFromRequest(msg); + Result logonResponse = await this.Mediator.Send(logonCommand, cancellationToken); + if (logonResponse.IsFailed) + return logonResponse.ToActionResultX(); dto = this.ModelFactory.ConvertFrom(logonResponse); break; case ReconciliationRequestMessage msg: - ProcessReconciliationRequest reconciliationRequest = this.CreateCommandFromRequest(msg); - ProcessReconciliationResponse reconciliationResponse = await this.Mediator.Send(reconciliationRequest, cancellationToken); + TransactionCommands.ProcessReconciliationCommand reconciliationCommand = this.CreateCommandFromRequest(msg); + Result reconciliationResponse = await this.Mediator.Send(reconciliationCommand, cancellationToken); + if (reconciliationResponse.IsFailed) + return reconciliationResponse.ToActionResultX(); dto = this.ModelFactory.ConvertFrom(reconciliationResponse); break; } - return this.Ok(dto); + + return Result.Success(dto).ToActionResultX(); } /// @@ -122,18 +127,18 @@ public async Task PerformTransaction([FromBody] TransactionReques /// /// The logon transaction request message. /// - private ProcessLogonTransactionRequest CreateCommandFromRequest(LogonTransactionRequestMessage logonTransactionRequestMessage) + private TransactionCommands.ProcessLogonTransactionCommand CreateCommandFromRequest(LogonTransactionRequestMessage logonTransactionRequestMessage) { Guid estateId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "estateId").Value); Guid merchantId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "merchantId").Value); - ProcessLogonTransactionRequest request = ProcessLogonTransactionRequest.Create(estateId, + TransactionCommands.ProcessLogonTransactionCommand command = new(estateId, merchantId, logonTransactionRequestMessage.TransactionDateTime, logonTransactionRequestMessage.TransactionNumber, logonTransactionRequestMessage.DeviceIdentifier); - return request; + return command; } /// @@ -141,12 +146,12 @@ private ProcessLogonTransactionRequest CreateCommandFromRequest(LogonTransaction /// /// The sale transaction request message. /// - private ProcessSaleTransactionRequest CreateCommandFromRequest(SaleTransactionRequestMessage saleTransactionRequestMessage) + private TransactionCommands.ProcessSaleTransactionCommand CreateCommandFromRequest(SaleTransactionRequestMessage saleTransactionRequestMessage) { Guid estateId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "estateId").Value); Guid merchantId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "merchantId").Value); - ProcessSaleTransactionRequest request = ProcessSaleTransactionRequest.Create(estateId, + TransactionCommands.ProcessSaleTransactionCommand command = new(estateId, merchantId, saleTransactionRequestMessage.TransactionDateTime, saleTransactionRequestMessage.TransactionNumber, @@ -157,7 +162,7 @@ private ProcessSaleTransactionRequest CreateCommandFromRequest(SaleTransactionRe saleTransactionRequestMessage.ProductId, saleTransactionRequestMessage.AdditionalRequestMetaData); - return request; + return command; } /// @@ -165,19 +170,19 @@ private ProcessSaleTransactionRequest CreateCommandFromRequest(SaleTransactionRe /// /// The reconciliation request message. /// - private ProcessReconciliationRequest CreateCommandFromRequest(ReconciliationRequestMessage reconciliationRequestMessage) + private TransactionCommands.ProcessReconciliationCommand CreateCommandFromRequest(ReconciliationRequestMessage reconciliationRequestMessage) { Guid estateId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "estateId").Value); Guid merchantId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "merchantId").Value); - ProcessReconciliationRequest request = ProcessReconciliationRequest.Create(estateId, + TransactionCommands.ProcessReconciliationCommand command = new(estateId, merchantId, reconciliationRequestMessage.TransactionDateTime, reconciliationRequestMessage.DeviceIdentifier, reconciliationRequestMessage.TransactionCount, reconciliationRequestMessage.TransactionValue); - return request; + return command; } #endregion diff --git a/TransactionProcessorACL/Controllers/VoucherController.cs b/TransactionProcessorACL/Controllers/VoucherController.cs index 38334cf..977c471 100644 --- a/TransactionProcessorACL/Controllers/VoucherController.cs +++ b/TransactionProcessorACL/Controllers/VoucherController.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; using System.Threading; using System; +using EstateManagement.Client; +using JasperFx.Core; +using SimpleResults; using TransactionProcessorACL.BusinessLogic.Common; using TransactionProcessorACL.BusinessLogic.Requests; using TransactionProcessorACL.Factories; @@ -16,7 +19,8 @@ namespace TransactionProcessorACL.Controllers using Models; using Shared.General; using Shared.Logger; - using RedeemVoucherRequest = BusinessLogic.Requests.RedeemVoucherRequest; + using static Microsoft.EntityFrameworkCore.DbLoggerCategory; + using static TransactionProcessorACL.BusinessLogic.Requests.VersionCheckCommands; [ExcludeFromCodeCoverage] [Route(VoucherController.ControllerRoute)] @@ -77,26 +81,22 @@ public async Task GetVoucher([FromQuery] String voucherCode, } // Do the software version check - try - { - VersionCheckRequest versionCheckRequest = VersionCheckRequest.Create(applicationVersion); - await this.Mediator.Send(versionCheckRequest, cancellationToken); - } - catch (VersionIncompatibleException vex) - { - Logger.LogError(vex); + VersionCheckCommand versionCheckCommand = new(applicationVersion); + var versionCheckResult = await this.Mediator.Send(versionCheckCommand, cancellationToken); + if (versionCheckResult.IsFailed) return this.StatusCode(505); - } - Guid estateId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "estateId").Value); - Guid contractId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "contractId").Value); + Guid estateId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "estateId").Data.Value); + Guid contractId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "contractId").Data.Value); // Now do the GET - GetVoucherRequest request = GetVoucherRequest.Create(estateId, contractId, voucherCode); + VoucherQueries.GetVoucherQuery query = new(estateId, contractId, voucherCode); - GetVoucherResponse response = await this.Mediator.Send(request, cancellationToken); + var result = await this.Mediator.Send(query, cancellationToken); + if (result.IsFailed) + return ResultHelpers.CreateFailure(result).ToActionResultX(); - return this.Ok(this.ModelFactory.ConvertFrom(response)); + return Result.Success(this.ModelFactory.ConvertFrom(result.Data)).ToActionResultX(); } /// @@ -120,26 +120,22 @@ public async Task RedeemVoucher([FromQuery] String voucherCode, } // Do the software version check - try - { - VersionCheckRequest versionCheckRequest = VersionCheckRequest.Create(applicationVersion); - await this.Mediator.Send(versionCheckRequest, cancellationToken); - } - catch (VersionIncompatibleException vex) - { - Logger.LogError(vex); + VersionCheckCommand versionCheckCommand = new(applicationVersion); + var versionCheckResult = await this.Mediator.Send(versionCheckCommand, cancellationToken); + if (versionCheckResult.IsFailed) return this.StatusCode(505); - } - Guid estateId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "estateId").Value); - Guid contractId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "contractId").Value); + Guid estateId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "estateId").Data.Value); + Guid contractId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "contractId").Data.Value); // Now do the GET - RedeemVoucherRequest request = RedeemVoucherRequest.Create(estateId, contractId, voucherCode); + VoucherCommands.RedeemVoucherCommand comamnd = new(estateId, contractId, voucherCode); - RedeemVoucherResponse response = await this.Mediator.Send(request, cancellationToken); + var result = await this.Mediator.Send(comamnd, cancellationToken); + if (result.IsFailed) + return ResultHelpers.CreateFailure(result).ToActionResultX(); - return this.Ok(this.ModelFactory.ConvertFrom(response)); + return Result.Success(this.ModelFactory.ConvertFrom(result.Data)).ToActionResultX(); } diff --git a/TransactionProcessorACL/TransactionProcessorACL.csproj b/TransactionProcessorACL/TransactionProcessorACL.csproj index a1f6e30..0228f83 100644 --- a/TransactionProcessorACL/TransactionProcessorACL.csproj +++ b/TransactionProcessorACL/TransactionProcessorACL.csproj @@ -26,7 +26,7 @@ - + From 79f4588ed0b3ae0724c90d71eadfb4549204d770 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Tue, 12 Nov 2024 17:17:56 +0000 Subject: [PATCH 2/2] workflow fixes --- .github/workflows/createrelease.yml | 4 ++-- .github/workflows/pullrequest.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml index b09b718..0c7fdc2 100644 --- a/.github/workflows/createrelease.yml +++ b/.github/workflows/createrelease.yml @@ -56,7 +56,7 @@ jobs: zip -r ../transactionprocessoracl.zip ./* - name: Upload the artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4.4.0 with: name: transactionprocessoracl path: transactionprocessoracl.zip @@ -108,7 +108,7 @@ jobs: steps: - name: Download the artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4.1.8 with: name: transactionprocessoracl diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index b6b75d0..813470e 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -34,7 +34,7 @@ jobs: - name: Run Integration Tests run: dotnet test "TransactionProcessorACL.IntegrationTests\TransactionProcessorACL.IntegrationTests.csproj" --filter Category=PRTest - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4.4.0 if: ${{ failure() }} with: name: tracelogs