From e3b50eefff81f63bf5bc401370d65f21780fc0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 7 Oct 2021 14:57:15 +0300 Subject: [PATCH] Added PaymentRequest aggregate root and mapped to EF Core --- .../PaymentRequests/PaymentRequestConsts.cs | 8 +++++ .../PaymentRequests/PaymentRequestState.cs | 9 +++++ .../src/Payment.Domain/PaymentDbProperties.cs | 2 +- .../PaymentRequests/PaymentRequest.cs | 33 +++++++++++++++++++ .../EntityFrameworkCore/IPaymentDbContext.cs | 8 ++--- .../EntityFrameworkCore/PaymentDbContext.cs | 5 ++- ...PaymentDbContextModelCreatingExtensions.cs | 23 +++++-------- 7 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestConsts.cs create mode 100644 modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestState.cs create mode 100644 modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs diff --git a/modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestConsts.cs b/modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestConsts.cs new file mode 100644 index 0000000..02574dc --- /dev/null +++ b/modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestConsts.cs @@ -0,0 +1,8 @@ +namespace Payment.PaymentRequests +{ + public static class PaymentRequestConsts + { + public const int MaxProductIdLength = 100; + public const int MaxProductNameLength = 200; + } +} \ No newline at end of file diff --git a/modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestState.cs b/modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestState.cs new file mode 100644 index 0000000..faa3bce --- /dev/null +++ b/modules/payment/src/Payment.Domain.Shared/PaymentRequests/PaymentRequestState.cs @@ -0,0 +1,9 @@ +namespace Payment.PaymentRequests +{ + public enum PaymentRequestState : byte + { + Waiting = 0, + Completed, + Failed + } +} \ No newline at end of file diff --git a/modules/payment/src/Payment.Domain/PaymentDbProperties.cs b/modules/payment/src/Payment.Domain/PaymentDbProperties.cs index 258bc24..ae502eb 100644 --- a/modules/payment/src/Payment.Domain/PaymentDbProperties.cs +++ b/modules/payment/src/Payment.Domain/PaymentDbProperties.cs @@ -2,7 +2,7 @@ { public static class PaymentDbProperties { - public static string DbTablePrefix { get; set; } = "Payment"; + public static string DbTablePrefix { get; set; } = "Pay"; public static string DbSchema { get; set; } = null; diff --git a/modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs b/modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs new file mode 100644 index 0000000..ae8c9ed --- /dev/null +++ b/modules/payment/src/Payment.Domain/PaymentRequests/PaymentRequest.cs @@ -0,0 +1,33 @@ +using System; +using JetBrains.Annotations; +using Volo.Abp; +using Volo.Abp.Domain.Entities.Auditing; + +namespace Payment.PaymentRequests +{ + public class PaymentRequest : CreationAuditedAggregateRoot + { + public string CustomerId { get; private set; } + + public string ProductId { get; private set; } + + [NotNull] + public string ProductName { get; private set; } + + public decimal Amount { get; private set; } + + public PaymentRequestState State { get; set; } + + public PaymentRequest( + Guid id, + [NotNull] string productName, + [CanBeNull] string productId, + decimal amount) + : base(id) + { + ProductName = Check.NotNullOrWhiteSpace(productName, nameof(productName)); + ProductId = productId; + Amount = amount; + } + } +} \ No newline at end of file diff --git a/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/IPaymentDbContext.cs b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/IPaymentDbContext.cs index 3259838..28e4b20 100644 --- a/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/IPaymentDbContext.cs +++ b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/IPaymentDbContext.cs @@ -1,4 +1,6 @@ -using Volo.Abp.Data; +using Microsoft.EntityFrameworkCore; +using Payment.PaymentRequests; +using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; namespace Payment.EntityFrameworkCore @@ -6,8 +8,6 @@ namespace Payment.EntityFrameworkCore [ConnectionStringName(PaymentDbProperties.ConnectionStringName)] public interface IPaymentDbContext : IEfCoreDbContext { - /* Add DbSet for each Aggregate Root here. Example: - * DbSet Questions { get; } - */ + DbSet PaymentRequests { get; } } } \ No newline at end of file diff --git a/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContext.cs b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContext.cs index aa87890..c2a066e 100644 --- a/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContext.cs +++ b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContext.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Payment.PaymentRequests; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; @@ -7,9 +8,7 @@ namespace Payment.EntityFrameworkCore [ConnectionStringName(PaymentDbProperties.ConnectionStringName)] public class PaymentDbContext : AbpDbContext, IPaymentDbContext { - /* Add DbSet for each Aggregate Root here. Example: - * public DbSet Questions { get; set; } - */ + public DbSet PaymentRequests { get; set; } public PaymentDbContext(DbContextOptions options) : base(options) diff --git a/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContextModelCreatingExtensions.cs b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContextModelCreatingExtensions.cs index 18c6740..512724e 100644 --- a/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContextModelCreatingExtensions.cs +++ b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/PaymentDbContextModelCreatingExtensions.cs @@ -1,5 +1,7 @@ using Microsoft.EntityFrameworkCore; +using Payment.PaymentRequests; using Volo.Abp; +using Volo.Abp.EntityFrameworkCore.Modeling; namespace Payment.EntityFrameworkCore { @@ -10,25 +12,16 @@ namespace Payment.EntityFrameworkCore { Check.NotNull(builder, nameof(builder)); - /* Configure all entities here. Example: - - builder.Entity(b => + builder.Entity(b => { - //Configure table & schema name - b.ToTable(PaymentDbProperties.DbTablePrefix + "Questions", PaymentDbProperties.DbSchema); - + b.ToTable(PaymentDbProperties.DbTablePrefix + "PaymentRequests", PaymentDbProperties.DbSchema); b.ConfigureByConvention(); + b.Property(x => x.ProductName).IsRequired().HasMaxLength(PaymentRequestConsts.MaxProductNameLength); + b.Property(x => x.ProductId).IsRequired().HasMaxLength(PaymentRequestConsts.MaxProductIdLength); - //Properties - b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength); - - //Relations - b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId); - - //Indexes - b.HasIndex(q => q.CreationTime); + b.HasIndex(x => x.CustomerId); + b.HasIndex(x => x.State); }); - */ } } }