From 45d2e940eb25a5bcf0615f241c65a77420890ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 7 Oct 2021 15:11:18 +0300 Subject: [PATCH] Added initial IPaymentRequestAppService --- .../IPaymentRequestAppService.cs | 10 +++++++ .../PaymentRequestCreationDto.cs | 17 +++++++++++ .../PaymentRequests/PaymentRequestDto.cs | 18 ++++++++++++ .../PaymentApplicationAutoMapperProfile.cs | 5 ++-- .../PaymentRequestAppService.cs | 29 +++++++++++++++++++ .../IPaymentRequestRepository.cs | 10 +++++++ .../PaymentRequests/PaymentRequest.cs | 8 +++-- .../Repositories/PaymentRequestRepository.cs | 15 ++++++++++ 8 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 modules/payment/src/Payment.Application.Contracts/PaymentRequests/IPaymentRequestAppService.cs create mode 100644 modules/payment/src/Payment.Application.Contracts/PaymentRequests/PaymentRequestCreationDto.cs create mode 100644 modules/payment/src/Payment.Application.Contracts/PaymentRequests/PaymentRequestDto.cs create mode 100644 modules/payment/src/Payment.Application/PaymentRequests/PaymentRequestAppService.cs create mode 100644 modules/payment/src/Payment.Domain/PaymentRequests/IPaymentRequestRepository.cs create mode 100644 modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/Repositories/PaymentRequestRepository.cs diff --git a/modules/payment/src/Payment.Application.Contracts/PaymentRequests/IPaymentRequestAppService.cs b/modules/payment/src/Payment.Application.Contracts/PaymentRequests/IPaymentRequestAppService.cs new file mode 100644 index 0000000..0467c6d --- /dev/null +++ b/modules/payment/src/Payment.Application.Contracts/PaymentRequests/IPaymentRequestAppService.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using Volo.Abp.Application.Services; + +namespace Payment.PaymentRequests +{ + public interface IPaymentRequestAppService : IApplicationService + { + Task CreateAsync(PaymentRequestCreationDto input); + } +} \ No newline at end of file diff --git a/modules/payment/src/Payment.Application.Contracts/PaymentRequests/PaymentRequestCreationDto.cs b/modules/payment/src/Payment.Application.Contracts/PaymentRequests/PaymentRequestCreationDto.cs new file mode 100644 index 0000000..78baab2 --- /dev/null +++ b/modules/payment/src/Payment.Application.Contracts/PaymentRequests/PaymentRequestCreationDto.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.ObjectExtending; + +namespace Payment.PaymentRequests +{ + public class PaymentRequestCreationDto : ExtensibleObject + { + public string CustomerId { get; set; } + + public string ProductId { get; set; } + + [Required] + public string ProductName { get; set; } + + public decimal Amount { get; set; } + } +} \ No newline at end of file diff --git a/modules/payment/src/Payment.Application.Contracts/PaymentRequests/PaymentRequestDto.cs b/modules/payment/src/Payment.Application.Contracts/PaymentRequests/PaymentRequestDto.cs new file mode 100644 index 0000000..528a6f1 --- /dev/null +++ b/modules/payment/src/Payment.Application.Contracts/PaymentRequests/PaymentRequestDto.cs @@ -0,0 +1,18 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace Payment.PaymentRequests +{ + public class PaymentRequestDto : CreationAuditedEntityDto + { + public string CustomerId { get; set; } + + public string ProductId { get; set; } + + public string ProductName { get; set; } + + public decimal Amount { get; set; } + + public PaymentRequestState State { get; set; } + } +} \ No newline at end of file diff --git a/modules/payment/src/Payment.Application/PaymentApplicationAutoMapperProfile.cs b/modules/payment/src/Payment.Application/PaymentApplicationAutoMapperProfile.cs index a15ddeb..bf8c80d 100644 --- a/modules/payment/src/Payment.Application/PaymentApplicationAutoMapperProfile.cs +++ b/modules/payment/src/Payment.Application/PaymentApplicationAutoMapperProfile.cs @@ -1,4 +1,5 @@ using AutoMapper; +using Payment.PaymentRequests; namespace Payment { @@ -6,9 +7,7 @@ namespace Payment { public PaymentApplicationAutoMapperProfile() { - /* You can configure your AutoMapper mapping configuration here. - * Alternatively, you can split your mapping configurations - * into multiple profile classes for a better organization. */ + CreateMap(); } } } \ No newline at end of file diff --git a/modules/payment/src/Payment.Application/PaymentRequests/PaymentRequestAppService.cs b/modules/payment/src/Payment.Application/PaymentRequests/PaymentRequestAppService.cs new file mode 100644 index 0000000..bfe3504 --- /dev/null +++ b/modules/payment/src/Payment.Application/PaymentRequests/PaymentRequestAppService.cs @@ -0,0 +1,29 @@ +using System.Threading.Tasks; + +namespace Payment.PaymentRequests +{ + public class PaymentRequestAppService : PaymentAppService, IPaymentRequestAppService + { + private readonly IPaymentRequestRepository _paymentRequestRepository; + + public PaymentRequestAppService(IPaymentRequestRepository paymentRequestRepository) + { + _paymentRequestRepository = paymentRequestRepository; + } + + public async Task CreateAsync(PaymentRequestCreationDto input) + { + var paymentRequest = new PaymentRequest( + GuidGenerator.Create(), + input.CustomerId, + input.ProductId, + input.ProductName, + input.Amount + ); + + await _paymentRequestRepository.InsertAsync(paymentRequest); + + return ObjectMapper.Map(paymentRequest); + } + } +} \ No newline at end of file diff --git a/modules/payment/src/Payment.Domain/PaymentRequests/IPaymentRequestRepository.cs b/modules/payment/src/Payment.Domain/PaymentRequests/IPaymentRequestRepository.cs new file mode 100644 index 0000000..1269daa --- /dev/null +++ b/modules/payment/src/Payment.Domain/PaymentRequests/IPaymentRequestRepository.cs @@ -0,0 +1,10 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace Payment.PaymentRequests +{ + public interface IPaymentRequestRepository : IRepository + { + + } +} \ No newline at end of file diff --git a/modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs b/modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs index ae8c9ed..80049b4 100644 --- a/modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs +++ b/modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs @@ -7,8 +7,10 @@ namespace Payment.PaymentRequests { public class PaymentRequest : CreationAuditedAggregateRoot { + [CanBeNull] public string CustomerId { get; private set; } + [CanBeNull] public string ProductId { get; private set; } [NotNull] @@ -20,13 +22,15 @@ namespace Payment.PaymentRequests public PaymentRequest( Guid id, - [NotNull] string productName, + [CanBeNull] string customerId, [CanBeNull] string productId, + [NotNull] string productName, decimal amount) : base(id) { - ProductName = Check.NotNullOrWhiteSpace(productName, nameof(productName)); + CustomerId = customerId; ProductId = productId; + ProductName = Check.NotNullOrWhiteSpace(productName, nameof(productName)); Amount = amount; } } diff --git a/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/Repositories/PaymentRequestRepository.cs b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/Repositories/PaymentRequestRepository.cs new file mode 100644 index 0000000..d0e236d --- /dev/null +++ b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/Repositories/PaymentRequestRepository.cs @@ -0,0 +1,15 @@ +using System; +using Payment.PaymentRequests; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace Payment.EntityFrameworkCore.Repositories +{ + public class PaymentRequestRepository : EfCoreRepository, IPaymentRequestRepository + { + public PaymentRequestRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + } +} \ No newline at end of file