diff --git a/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs b/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs index 13f6cb1..c9f1ffa 100644 --- a/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs +++ b/TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs @@ -35,6 +35,7 @@ public MediatorTests() this.Requests.Add(TestData.RedeemVoucherCommand); this.Requests.Add(TestData.GetMerchantContractsQuery); this.Requests.Add(TestData.GetMerchantQuery); + this.Requests.Add(TestData.GetMerchantScheduleQuery); } [Fact] @@ -152,5 +153,12 @@ public async Task> GetMerchant(Guid estateId, CancellationToken cancellationToken) { return Result.Success(new MerchantResponse()); } + + public async Task> GetMerchantSchedule(Guid estateId, + Guid merchantId, + Int32 year, + CancellationToken cancellationToken) { + return Result.Success(new MerchantScheduleResponse()); + } } } diff --git a/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACLApplicationServiceTests.cs b/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACLApplicationServiceTests.cs index 294a5dc..8dad0f8 100644 --- a/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACLApplicationServiceTests.cs +++ b/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACLApplicationServiceTests.cs @@ -371,7 +371,7 @@ public async Task TransactionProcessorACLApplicationService_ProcessReconciliatio } [Fact] - public async Task VoucherManagementACLApplicationService_GetVoucher_VoucherRetrieved() + public async Task TransactionProcessorACLApplicationService_GetVoucher_VoucherRetrieved() { this.transactionProcessorClient.Setup(v => v.GetVoucherByCode(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetVoucherResponse); @@ -390,7 +390,7 @@ public async Task VoucherManagementACLApplicationService_GetVoucher_VoucherRetri } [Fact] - public async Task VoucherManagementACLApplicationService_GetVoucher_GetTokenFailed_ResultIsFailed() + public async Task TransactionProcessorACLApplicationService_GetVoucher_GetTokenFailed_ResultIsFailed() { securityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure()); @@ -400,7 +400,7 @@ public async Task VoucherManagementACLApplicationService_GetVoucher_GetTokenFail } [Fact] - public async Task VoucherManagementACLApplicationService_GetVoucher_GetVoucherFailed_ResultIsFailed() + public async Task TransactionProcessorACLApplicationService_GetVoucher_GetVoucherFailed_ResultIsFailed() { this.transactionProcessorClient.Setup(v => v.GetVoucherByCode(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Failure()); @@ -412,7 +412,7 @@ public async Task VoucherManagementACLApplicationService_GetVoucher_GetVoucherFa } [Fact] - public async Task VoucherManagementACLApplicationService_GetVoucher_ExceptionErrorInGetVoucher_GetVoucherIsNotSuccessful() + public async Task TransactionProcessorACLApplicationService_GetVoucher_ExceptionErrorInGetVoucher_GetVoucherIsNotSuccessful() { transactionProcessorClient.Setup(v => v.GetVoucherByCode(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ThrowsAsync(new Exception("Error")); @@ -424,7 +424,7 @@ public async Task VoucherManagementACLApplicationService_GetVoucher_ExceptionErr } [Fact] - public async Task VoucherManagementACLApplicationService_RedeemVoucher_VoucherRedeemed() + public async Task TransactionProcessorACLApplicationService_RedeemVoucher_VoucherRedeemed() { transactionProcessorClient.Setup(v => v.RedeemVoucher(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success); @@ -438,7 +438,7 @@ public async Task VoucherManagementACLApplicationService_RedeemVoucher_VoucherRe } [Fact] - public async Task VoucherManagementACLApplicationService_RedeemVoucher_GetTokenFailed_ResultIsFailed() + public async Task TransactionProcessorACLApplicationService_RedeemVoucher_GetTokenFailed_ResultIsFailed() { transactionProcessorClient.Setup(v => v.RedeemVoucher(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Failure); @@ -450,7 +450,7 @@ public async Task VoucherManagementACLApplicationService_RedeemVoucher_GetTokenF } [Fact] - public async Task VoucherManagementACLApplicationService_RedeemVoucher_RedeemVoucherFailed_ResultIsFailed() + public async Task TransactionProcessorACLApplicationService_RedeemVoucher_RedeemVoucherFailed_ResultIsFailed() { transactionProcessorClient.Setup(v => v.RedeemVoucher(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Failure()); @@ -462,7 +462,7 @@ public async Task VoucherManagementACLApplicationService_RedeemVoucher_RedeemVou } [Fact] - public async Task VoucherManagementACLApplicationService_RedeemVoucher_ExceptionErrorInGetVoucher_GetVoucherIsNotSuccessful() + public async Task TransactionProcessorACLApplicationService_RedeemVoucher_ExceptionErrorInGetVoucher_GetVoucherIsNotSuccessful() { transactionProcessorClient.Setup(v => v.RedeemVoucher(It.IsAny(), It.IsAny(), It.IsAny())) .ThrowsAsync(new Exception("Error")); @@ -478,7 +478,7 @@ public async Task VoucherManagementACLApplicationService_RedeemVoucher_Exception [InlineData(TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Immediate)] [InlineData(TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Weekly)] [InlineData(TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule.Monthly)] - public async Task VoucherManagementACLApplicationService_GetMerchant_MerchantReturned(TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule settlementSchedule) + public async Task TransactionProcessorACLApplicationService_GetMerchant_MerchantReturned(TransactionProcessor.DataTransferObjects.Responses.Merchant.SettlementSchedule settlementSchedule) { transactionProcessorClient.Setup(v => v.GetMerchant(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.MerchantResponse(settlementSchedule))); @@ -504,7 +504,7 @@ public async Task VoucherManagementACLApplicationService_GetMerchant_MerchantRet } [Fact] - public async Task VoucherManagementACLApplicationService_GetMerchant_GetTokenFailed_ResultIsFailed() + public async Task TransactionProcessorACLApplicationService_GetMerchant_GetTokenFailed_ResultIsFailed() { securityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure()); @@ -514,7 +514,7 @@ public async Task VoucherManagementACLApplicationService_GetMerchant_GetTokenFai } [Fact] - public async Task VoucherManagementACLApplicationService_GetMerchant_GetMerchantFailed_ResultIsFailed() + public async Task TransactionProcessorACLApplicationService_GetMerchant_GetMerchantFailed_ResultIsFailed() { transactionProcessorClient.Setup(v => v.GetMerchant(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Failure()); @@ -528,7 +528,7 @@ public async Task VoucherManagementACLApplicationService_GetMerchant_GetMerchant [InlineData(TransactionProcessor.DataTransferObjects.Responses.Contract.ProductType.Voucher)] [InlineData(TransactionProcessor.DataTransferObjects.Responses.Contract.ProductType.BillPayment)] [InlineData(TransactionProcessor.DataTransferObjects.Responses.Contract.ProductType.MobileTopup)] - public async Task VoucherManagementACLApplicationService_GetMerchantContracts_MerchantContractsReturned(TransactionProcessor.DataTransferObjects.Responses.Contract.ProductType productType) { + public async Task TransactionProcessorACLApplicationService_GetMerchantContracts_MerchantContractsReturned(TransactionProcessor.DataTransferObjects.Responses.Contract.ProductType productType) { transactionProcessorClient.Setup(v => v.GetMerchantContracts(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.MerchantContractResponses(productType))); securityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.TokenResponse)); @@ -538,7 +538,7 @@ public async Task VoucherManagementACLApplicationService_GetMerchantContracts_Me } [Fact] - public async Task VoucherManagementACLApplicationService_GetMerchantContracts_GetTokenFailed_ResultIsFailed() + public async Task TransactionProcessorACLApplicationService_GetMerchantContracts_GetTokenFailed_ResultIsFailed() { securityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure()); @@ -547,7 +547,7 @@ public async Task VoucherManagementACLApplicationService_GetMerchantContracts_Ge } [Fact] - public async Task VoucherManagementACLApplicationService_GetMerchantContracts_GetMerchantContractsFailed_ResultIsFailed() + public async Task TransactionProcessorACLApplicationService_GetMerchantContracts_GetMerchantContractsFailed_ResultIsFailed() { transactionProcessorClient.Setup(v => v.GetMerchantContracts(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Failure()); @@ -556,5 +556,36 @@ public async Task VoucherManagementACLApplicationService_GetMerchantContracts_Ge var merchantContractsResponse = await applicationService.GetMerchantContracts(TestData.EstateId, TestData.MerchantId, CancellationToken.None); merchantContractsResponse.IsFailed.ShouldBeTrue(); } + + [Fact] + public async Task TransactionProcessorACLApplicationService_GetMerchantSchedule_MerchantScheduleReturned() + { + transactionProcessorClient.Setup(v => v.GetMerchantSchedule(It.IsAny(), It.IsAny(), It.IsAny(),It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.MerchantScheduleResponse())); + securityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.TokenResponse)); + + var merchantScheduleResponse = await applicationService.GetMerchantSchedule(TestData.EstateId, TestData.MerchantId, TestData.ScheduleYear, CancellationToken.None); + merchantScheduleResponse.IsSuccess.ShouldBeTrue(); + } + + [Fact] + public async Task TransactionProcessorACLApplicationService_GetMerchantSchedule_GetTokenFailed_ResultIsFailed() + { + securityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure()); + + var merchantScheduleResponse = await applicationService.GetMerchantSchedule(TestData.EstateId, TestData.MerchantId, TestData.ScheduleYear, CancellationToken.None); + merchantScheduleResponse.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task TransactionProcessorACLApplicationService_GetMerchantSchedule_GetMerchantScheduleFailed_ResultIsFailed() + { + transactionProcessorClient.Setup(v => v.GetMerchantSchedule(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + securityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.TokenResponse)); + + var merchantScheduleResponse = await applicationService.GetMerchantSchedule(TestData.EstateId, TestData.MerchantId, TestData.ScheduleYear, CancellationToken.None); + merchantScheduleResponse.IsFailed.ShouldBeTrue(); + } } } diff --git a/TransactionProcessorACL.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs b/TransactionProcessorACL.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs index 8629eeb..ac25f8a 100644 --- a/TransactionProcessorACL.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs +++ b/TransactionProcessorACL.BusinessLogic/RequestHandlers/MerchantRequestHandler.cs @@ -10,13 +10,11 @@ namespace TransactionProcessorACL.BusinessLogic.RequestHandlers; public class MerchantRequestHandler : IRequestHandler>>, -IRequestHandler> { - #region Fields - +IRequestHandler>, +IRequestHandler> { + private readonly ITransactionProcessorACLApplicationService ApplicationService; - - #endregion - + public MerchantRequestHandler(ITransactionProcessorACLApplicationService applicationService) { this.ApplicationService = applicationService; } @@ -30,4 +28,9 @@ public async Task> Handle(MerchantQueries.GetMerchantQu CancellationToken cancellationToken) { return await this.ApplicationService.GetMerchant(request.EstateId, request.MerchantId, cancellationToken); } + + public async Task> Handle(MerchantQueries.GetMerchantScheduleQuery request, + CancellationToken cancellationToken) { + return await this.ApplicationService.GetMerchantSchedule(request.EstateId, request.MerchantId, request.Year, cancellationToken); + } } \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Requests/MerchantQueries.cs b/TransactionProcessorACL.BusinessLogic/Requests/MerchantQueries.cs new file mode 100644 index 0000000..315e518 --- /dev/null +++ b/TransactionProcessorACL.BusinessLogic/Requests/MerchantQueries.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using MediatR; +using SimpleResults; +using TransactionProcessorACL.Models; + +namespace TransactionProcessorACL.BusinessLogic.Requests; + +[ExcludeFromCodeCoverage] +public record MerchantQueries { + public record GetMerchantContractsQuery(Guid EstateId,Guid MerchantId) : IRequest>>; + public record GetMerchantQuery(Guid EstateId, Guid MerchantId) : IRequest>; + public record GetMerchantScheduleQuery(Guid EstateId, Guid MerchantId, Int32 Year) : IRequest>; + +} \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs b/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs index 5d0ff8f..6ac5238 100644 --- a/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs +++ b/TransactionProcessorACL.BusinessLogic/Requests/TransactionCommands.cs @@ -5,7 +5,6 @@ using SimpleResults; using TransactionProcessor.DataTransferObjects.Responses.Merchant; using TransactionProcessorACL.Models; -using MerchantResponse = TransactionProcessorACL.Models.MerchantResponse; namespace TransactionProcessorACL.BusinessLogic.Requests; @@ -37,11 +36,4 @@ public record ProcessReconciliationCommand(Guid EstateId, Int32 TransactionCount, Decimal TransactionValue) : IRequest>; -} - -[ExcludeFromCodeCoverage] -public record MerchantQueries { - public record GetMerchantContractsQuery(Guid EstateId,Guid MerchantId) : IRequest>>; - public record GetMerchantQuery(Guid EstateId, Guid MerchantId) : IRequest>; - } \ No newline at end of file diff --git a/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs index 007c102..4f042bb 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/ITransactionProcessorACLApplicationService.cs @@ -55,5 +55,10 @@ Task> RedeemVoucher(Guid estateId, Task> GetMerchant(Guid estateId, Guid merchantId, CancellationToken cancellationToken); + + Task> GetMerchantSchedule(Guid estateId, + Guid merchantId, + Int32 year, + CancellationToken cancellationToken); } } diff --git a/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs b/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs index bef1087..b26405d 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/ResponseFactory.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using TransactionProcessor.DataTransferObjects.Requests.Merchant; using TransactionProcessorACL.Models; using ContractContactResponse = TransactionProcessor.DataTransferObjects.Responses.Contract.ContactResponse; @@ -138,5 +139,23 @@ private static void PopulateMerchantOperators(List new MerchantScheduleMonthResponse + { + Month = m.Month, + ClosedDays = m.ClosedDays + }).ToList() ?? new List() + }; + + return response; + } } } diff --git a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs index b8bfd7e..bb54bc9 100644 --- a/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs +++ b/TransactionProcessorACL.BusinessLogic/Services/TransactionProcessorACLApplicationService.cs @@ -397,7 +397,29 @@ public async Task> GetMerchant(Guid estateId, MerchantResponse merchantResponse = ResponseFactory.Build(result.Data); - return merchantResponse; + return Result.Success(merchantResponse); + } + + public async Task> GetMerchantSchedule(Guid estateId, + Guid merchantId, + Int32 year, + CancellationToken cancellationToken) { + Result accessTokenResult = await this.GetAccessToken(cancellationToken); + if (accessTokenResult.IsFailed) + { + return ResultHelpers.CreateFailure(accessTokenResult); + } + + TokenResponse accessToken = accessTokenResult.Data; + + Result result = await this.TransactionProcessorClient.GetMerchantSchedule(accessToken.AccessToken, estateId, merchantId, year, cancellationToken); + + if (result.IsFailed) + return Result.Failure($"Error getting merchant schedule {result.Message}"); + + MerchantScheduleResponse merchantScheduleResponse = ResponseFactory.Build(result.Data); + + return Result.Success(merchantScheduleResponse); } private static ProcessReconciliationResponse CreateProcessReconciliationResponse(ReconciliationResponse reconciliationResponse) diff --git a/TransactionProcessorACL.DataTransferObjects/Responses/RedeemVoucherResponseMessage.cs b/TransactionProcessorACL.DataTransferObjects/Responses/RedeemVoucherResponseMessage.cs index 13a99c7..f5565c7 100644 --- a/TransactionProcessorACL.DataTransferObjects/Responses/RedeemVoucherResponseMessage.cs +++ b/TransactionProcessorACL.DataTransferObjects/Responses/RedeemVoucherResponseMessage.cs @@ -1,6 +1,7 @@ namespace TransactionProcessorACL.DataTransferObjects.Responses{ using System; + using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; [ExcludeFromCodeCoverage] @@ -23,4 +24,20 @@ public class RedeemVoucherResponseMessage{ #endregion } + + [ExcludeFromCodeCoverage] + public class MerchantScheduleResponse + { + public int Year { get; set; } + + public List Months { get; set; } = new List(); + } + + [ExcludeFromCodeCoverage] + public class MerchantScheduleMonthResponse + { + public int Month { get; set; } + + public List ClosedDays { get; set; } = new List(); + } } \ No newline at end of file diff --git a/TransactionProcessorACL.Models/MerchantResponse.cs b/TransactionProcessorACL.Models/MerchantResponse.cs index 58ad5fb..7434b3c 100644 --- a/TransactionProcessorACL.Models/MerchantResponse.cs +++ b/TransactionProcessorACL.Models/MerchantResponse.cs @@ -111,4 +111,19 @@ public class OpeningHoursResponse public string Closing { get; set; } } + + public class MerchantScheduleResponse + { + public int Year { get; set; } + + public List Months { get; set; } = new List(); + } + + public class MerchantScheduleMonthResponse + { + public int Month { get; set; } + + public List ClosedDays { get; set; } = new List(); + } + } diff --git a/TransactionProcessorACL.Testing/TestData.cs b/TransactionProcessorACL.Testing/TestData.cs index 988a80c..79fcf3b 100644 --- a/TransactionProcessorACL.Testing/TestData.cs +++ b/TransactionProcessorACL.Testing/TestData.cs @@ -53,6 +53,8 @@ public class TestData /// public static Guid MerchantId = Guid.Parse("1C8354B7-B97A-46EA-9AD1-C43F33F7E3C3"); + public static Int32 ScheduleYear = 2026; + /// /// The process logon transaction request /// @@ -200,6 +202,7 @@ public class TestData public static VoucherCommands.RedeemVoucherCommand RedeemVoucherCommand => new(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); public static MerchantQueries.GetMerchantContractsQuery GetMerchantContractsQuery => new(EstateId,MerchantId); public static MerchantQueries.GetMerchantQuery GetMerchantQuery => new(EstateId, MerchantId); + public static MerchantQueries.GetMerchantScheduleQuery GetMerchantScheduleQuery => new(EstateId, MerchantId, 2026); public static VoucherQueries.GetVoucherQuery GetVoucherQuery => new(TestData.EstateId, TestData.ContractId, TestData.VoucherCode); @@ -354,5 +357,9 @@ public static TransactionProcessor.DataTransferObjects.Responses.Merchant.Mercha } } }; + + public static TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantScheduleResponse MerchantScheduleResponse() { + return new TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantScheduleResponse { Year = ScheduleYear, Months = new List() { new TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantScheduleMonthResponse { ClosedDays = new List { 1, 2 }, Month = 1 }, new TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantScheduleMonthResponse { ClosedDays = new List { 25, 26 }, Month = 12 } } }; + } } } \ No newline at end of file diff --git a/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs b/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs index a39b398..e1edf6e 100644 --- a/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs +++ b/TransactionProcessorACL/Bootstrapper/MediatorRegistry.cs @@ -38,6 +38,7 @@ public MediatorRegistry() this.AddSingleton>>, MerchantRequestHandler>(); this.AddSingleton>, MerchantRequestHandler>(); + this.AddSingleton>, MerchantRequestHandler>(); } #endregion diff --git a/TransactionProcessorACL/Bootstrapper/MiddlewareRegistry.cs b/TransactionProcessorACL/Bootstrapper/MiddlewareRegistry.cs index 4946d78..a0121c9 100644 --- a/TransactionProcessorACL/Bootstrapper/MiddlewareRegistry.cs +++ b/TransactionProcessorACL/Bootstrapper/MiddlewareRegistry.cs @@ -34,7 +34,6 @@ public class MiddlewareRegistry : ServiceRegistry public MiddlewareRegistry() { this.ConfigureHealthChecks(); - this.ConfigureSwagger(); this.ConfigureAuthentication(); this.ConfigurePasswordTokenHandling(); this.ConfigureJsonOptions(); @@ -119,46 +118,6 @@ private void ConfigurePasswordTokenHandling() this.AddPasswordTokenPolicy(); this.AddPasswordTokenHandler(); } - - private void ConfigureSwagger() - { - this.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo - { - Title = "Transaction Processor ACL", - Version = "1.0", - Description = "A REST Api to provide and Anti Corruption Layer for the Transaction Mobile Application", - Contact = new OpenApiContact - { - Name = "Stuart Ferguson", - Email = "golfhandicapping@btinternet.com" - } - }); - c.UseAllOfForInheritance(); - c.SelectSubTypesUsing(baseType => - { - return typeof(TransactionRequestMessage).Assembly.GetTypes().Where(type => type.IsSubclassOf(baseType)); - }); - c.SelectSubTypesUsing(baseType => - { - return typeof(TransactionResponseMessage).Assembly.GetTypes().Where(type => type.IsSubclassOf(baseType)); - }); - // add a custom operation filter which sets default values - - c.ExampleFilters(); - - //Locate the XML files being generated by ASP.NET... - var directory = new DirectoryInfo(AppContext.BaseDirectory); - var xmlFiles = directory.GetFiles("*.xml"); - - //... and tell Swagger to use those XML comments. - foreach (FileInfo fileInfo in xmlFiles) - { - c.IncludeXmlComments(fileInfo.FullName); - } - }); - } } public static class JsonSerializerConfiguration diff --git a/TransactionProcessorACL/Endpoints/MerchantEndpoints.cs b/TransactionProcessorACL/Endpoints/MerchantEndpoints.cs index e60ec38..3671cc0 100644 --- a/TransactionProcessorACL/Endpoints/MerchantEndpoints.cs +++ b/TransactionProcessorACL/Endpoints/MerchantEndpoints.cs @@ -23,6 +23,8 @@ public static IEndpointRouteBuilder MapMerchantEndpoints(this IEndpointRouteBuil group.MapGet("contracts",MerchantHandlers.GetMerchantContracts).WithName("GetMerchantContracts"); + group.MapGet("schedules", MerchantHandlers.GetMerchantSchedule).WithName("GetMerchantSchedule"); + return app; } } diff --git a/TransactionProcessorACL/Factories/ModelFactory.cs b/TransactionProcessorACL/Factories/ModelFactory.cs index d55999c..6bbc0c2 100644 --- a/TransactionProcessorACL/Factories/ModelFactory.cs +++ b/TransactionProcessorACL/Factories/ModelFactory.cs @@ -1,3 +1,5 @@ +using System.Linq; + namespace TransactionProcessorACL.Factories { using System; @@ -286,5 +288,23 @@ public static RedeemVoucherResponseMessage ConvertFrom(RedeemVoucherResponse mod return responseMessage; } + + public static DataTransferObjects.Responses.MerchantScheduleResponse ConvertFrom(Models.MerchantScheduleResponse model) { + if (model == null) { + return null; + } + + DataTransferObjects.Responses.MerchantScheduleResponse response = new DataTransferObjects.Responses.MerchantScheduleResponse + { + Year = model.Year, + Months = model.Months?.Select(m => new DataTransferObjects.Responses.MerchantScheduleMonthResponse + { + Month = m.Month, + ClosedDays = m.ClosedDays + }).ToList() ?? new List() + }; + + return response; + } } } diff --git a/TransactionProcessorACL/Handlers/MerchantHandlers.cs b/TransactionProcessorACL/Handlers/MerchantHandlers.cs index c883fc0..d1b3174 100644 --- a/TransactionProcessorACL/Handlers/MerchantHandlers.cs +++ b/TransactionProcessorACL/Handlers/MerchantHandlers.cs @@ -7,6 +7,7 @@ using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Shared.Logger; using Shared.Results.Web; using SimpleResults; @@ -51,6 +52,24 @@ public static async Task GetMerchant(IMediator mediator, return ResponseFactory.FromResult(result, ModelFactory.ConvertFrom); } + + public static async Task GetMerchantSchedule(IMediator mediator, + ClaimsPrincipal user, + string applicationVersion, + [FromQuery] Int32 year, + CancellationToken cancellationToken) + { + Logger.LogWarning("In GetMerchantSchedule Handler"); + + Result<(Guid estateId, Guid merchantId)> claimsResult = Helpers.GetRequiredClaims(user); + if (claimsResult.IsFailed) + return ResponseFactory.FromResult(Result.Forbidden()); + + MerchantQueries.GetMerchantScheduleQuery query = new(claimsResult.Data.estateId, claimsResult.Data.merchantId, year); + Result result = await mediator.Send(query, cancellationToken); + + return ResponseFactory.FromResult(result, ModelFactory.ConvertFrom); + } } } diff --git a/TransactionProcessorACL/Startup.cs b/TransactionProcessorACL/Startup.cs index 5ae1751..2aa0792 100644 --- a/TransactionProcessorACL/Startup.cs +++ b/TransactionProcessorACL/Startup.cs @@ -71,7 +71,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF InitializeLogger(loggerFactory); ConfigureMiddleware(app); ConfigureEndpoints(app); - ConfigureSwagger(app); } private static void UseDevelopmentExceptionPage(IApplicationBuilder app, @@ -107,12 +106,6 @@ private static void ConfigureEndpoints(IApplicationBuilder app) app.UseEndpoints(MapEndpoints); } - private static void ConfigureSwagger(IApplicationBuilder app) - { - app.UseSwagger(); - app.UseSwaggerUI(); - } - private static void MapEndpoints(IEndpointRouteBuilder endpoints) { endpoints.MapMerchantEndpoints();