From 8156d79f241439346f285fc6b2aacc0e61e71c34 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Wed, 4 Oct 2023 21:18:54 +0330 Subject: [PATCH] fix some service dependency --- .../Helpers/AppUnitOfWork.cs | 9 ++++++--- .../Validations/ServiceEntityValidation.cs | 3 ++- .../TestBase.cs | 2 +- .../Controllers/OrderPortalController.cs | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/CSharp/EasyMicroservices.PaymentsMicroservice.Logics/Helpers/AppUnitOfWork.cs b/src/CSharp/EasyMicroservices.PaymentsMicroservice.Logics/Helpers/AppUnitOfWork.cs index e5339d8..dd6d947 100644 --- a/src/CSharp/EasyMicroservices.PaymentsMicroservice.Logics/Helpers/AppUnitOfWork.cs +++ b/src/CSharp/EasyMicroservices.PaymentsMicroservice.Logics/Helpers/AppUnitOfWork.cs @@ -29,14 +29,17 @@ public IConfiguration GetConfiguration() public async Task> GetPayment() { - var serviceId = await GetReadableOf().Select(x => x.Id).FirstOrDefaultAsync(); - return await GetPayment(serviceId); + var service = await GetReadableOf().FirstOrDefaultAsync(); + return await GetPayment((service?.Id).GetValueOrDefault()); } public async Task> GetPayment(long serviceId) { var service = await GetReadableOf().Include(x => x.Addresses).FirstOrDefaultAsync(x => x.Id == serviceId); - service.Validate(); + Console.WriteLine($"{serviceId} {service == null}"); + var validate = service.Validate(); + if (!validate) + return validate.ToContract(); var address = service.Addresses.First(); return new StripeProvider(address.ApiKey, new StripeClient(address.ApiKey, apiBase: address.Address)); } diff --git a/src/CSharp/EasyMicroservices.PaymentsMicroservice.Logics/Validations/ServiceEntityValidation.cs b/src/CSharp/EasyMicroservices.PaymentsMicroservice.Logics/Validations/ServiceEntityValidation.cs index adca21f..8849f04 100644 --- a/src/CSharp/EasyMicroservices.PaymentsMicroservice.Logics/Validations/ServiceEntityValidation.cs +++ b/src/CSharp/EasyMicroservices.PaymentsMicroservice.Logics/Validations/ServiceEntityValidation.cs @@ -1,6 +1,7 @@ using EasyMicroservices.PaymentsMicroservice.Database.Entities; using EasyMicroservices.ServiceContracts; using Microsoft.IdentityModel.Tokens; +using System.Linq; using System.Text; namespace EasyMicroservices.PaymentsMicroservice.Validations @@ -11,7 +12,7 @@ public static MessageContract Validate(this ServiceEntity service) { if (service == null) return (FailedReasonType.NotFound, "No service provider found in ServiceEntity, Please add your service provider!"); - else if (service.Addresses.IsNullOrEmpty()) + else if (service.Addresses.IsEmpty()) return (FailedReasonType.Empty, $"No address found for service provider Id: {service.Id}"); return true; } diff --git a/src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs b/src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs index 25ce9a7..f88f569 100644 --- a/src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs +++ b/src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs @@ -93,7 +93,7 @@ await queryable.AddAsync(new ServiceEntity() new ServiceAddressEntity() { //ApiKey = "your live session", - //Address = StripeClient.DefaultApiBase + //Address = Stripe.StripeClient.DefaultApiBase ApiKey = "testapikey", Address = $"http://localhost:{PaymentComponentPort}" } diff --git a/src/CSharp/EasyMicroservices.PaymentsMicroservice.WebApi/Controllers/OrderPortalController.cs b/src/CSharp/EasyMicroservices.PaymentsMicroservice.WebApi/Controllers/OrderPortalController.cs index de8669c..c5cf023 100644 --- a/src/CSharp/EasyMicroservices.PaymentsMicroservice.WebApi/Controllers/OrderPortalController.cs +++ b/src/CSharp/EasyMicroservices.PaymentsMicroservice.WebApi/Controllers/OrderPortalController.cs @@ -25,6 +25,7 @@ public async Task> CreateOrderPorta { var orderContractLogic = _unitOfWork.GetLongContractLogic(); var orderLogic = _unitOfWork.GetLogic(); + request.ServiceId = 1; var addedOrderId = await orderContractLogic.Add(request, cancellationToken).AsCheckedResult(); await OrderLogic.AddAndUpdateOrderStatus(addedOrderId, Payments.DataTypes.PaymentStatusType.Created , _unitOfWork); var paymentOrderResponse = await OrderLogic.CreateOrder(request, _unitOfWork);