From 2479b2588ff7cacfd8f6d5c0274bf1e518a27262 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 12:39:12 +0300 Subject: [PATCH] Added PaymentRequest data --- .../Orders/OrderConstants.cs | 2 + .../Orders/Order.cs | 13 +- .../Orders/OrderItem.cs | 3 +- .../Orders/OrderManager.cs | 12 +- .../OrderingServiceDbContext.cs | 1 + ...dded_Order_PaymentRequest_Info.Designer.cs | 248 ++++++++++++++++++ ...4093641_Added_Order_PaymentRequest_Info.cs | 47 ++++ .../OrderingServiceDbContextModelSnapshot.cs | 8 +- 8 files changed, 323 insertions(+), 11 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104093641_Added_Order_PaymentRequest_Info.Designer.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104093641_Added_Order_PaymentRequest_Info.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs index 7a01ed08..2409e42b 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs @@ -4,4 +4,6 @@ public static class OrderConstants { public const int OrderPaymentTypeNameMaxLength = 128; public const int OrderStatusNameMaxLength = 256; + public const int PaymentStatusMaxLength = 256; + } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs index 50e91850..426ab6a3 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -10,7 +10,8 @@ public class Order : AggregateRoot private int _orderStatusId; public DateTime OrderDate { get; private set; } public Guid? BuyerId { get; private set; } - public string PaymentMethodToken { get; private set; } // Payment token for validation + public Guid? PaymentRequestId { get; private set; } + public string PaymentStatus { get; private set; } public Address Address { get; private set; } public OrderStatus OrderStatus { get; private set; } public List OrderItems { get; private set; } @@ -19,14 +20,14 @@ public class Order : AggregateRoot { } - internal Order(Guid id, Address address, Guid? buyerId = null, string paymentMethodToken = null) : base(id) + internal Order(Guid id, Address address, Guid? buyerId = null, Guid? paymentRequestId = null) : base(id) { _orderStatusId = OrderStatus.Placed.Id; - OrderStatus = OrderStatus.Placed; OrderDate = DateTime.UtcNow; Address = address; BuyerId = buyerId; - PaymentMethodToken = paymentMethodToken; + PaymentRequestId = paymentRequestId; + PaymentStatus = "Waiting"; // TODO: magic string OrderItems = new List(); } @@ -37,7 +38,7 @@ public class Order : AggregateRoot return this; } - public Order AddOrderItem(Guid productId, string productName, string productCode, decimal unitPrice, + public Order AddOrderItem(Guid id, Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, string pictureUrl, int units = 1) { var existingOrderForProduct = OrderItems.SingleOrDefault(o => o.ProductId == productId); @@ -53,7 +54,7 @@ public class Order : AggregateRoot } else { - var orderItem = new OrderItem(productId, productName, productCode, unitPrice, discount, pictureUrl, units); + var orderItem = new OrderItem(id, productId, productName, productCode, unitPrice, discount, pictureUrl, units); OrderItems.Add(orderItem); } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs index 8a56bcd9..37ae25bf 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs @@ -17,7 +17,8 @@ public class OrderItem : Entity protected OrderItem() { } - public OrderItem(Guid productId, [NotNull]string productName, [NotNull]string productCode, decimal unitPrice, decimal discount, [CanBeNull]string pictureUrl, int units = 1) + public OrderItem(Guid id, Guid productId, [NotNull]string productName, [NotNull]string productCode, decimal unitPrice, decimal discount, [CanBeNull]string pictureUrl, int units = 1) + : base(id) { if (units <= 0) { diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs index 2007aca7..abec3d92 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.Threading.Tasks; using EShopOnAbp.OrderingService.Buyers; using Volo.Abp; +using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Services; using Volo.Abp.EventBus.Distributed; +using Volo.Abp.Uow; namespace EShopOnAbp.OrderingService.Orders; @@ -13,15 +15,17 @@ public class OrderManager : DomainService private readonly IOrderRepository _orderRepository; private readonly IBuyerRepository _buyerRepository; private readonly IDistributedEventBus _distributedEventBus; + private readonly UnitOfWorkManager _unitOfWorkManager; public OrderManager( IOrderRepository orderRepository, IBuyerRepository buyerRepository, - IDistributedEventBus distributedEventBus) + IDistributedEventBus distributedEventBus, UnitOfWorkManager unitOfWorkManager) { _orderRepository = orderRepository; _buyerRepository = buyerRepository; _distributedEventBus = distributedEventBus; + _unitOfWorkManager = unitOfWorkManager; } public async Task CreateOrderAsync( @@ -44,6 +48,8 @@ public class OrderManager : DomainService autoSave: true ); + var insertedBuyer = await _buyerRepository.GetAsync(buyer.Id, includeDetails: true); + // Create new order Order order = new Order( id: GuidGenerator.Create(), @@ -59,6 +65,7 @@ public class OrderManager : DomainService foreach (var orderItem in orderItems) { order.AddOrderItem( + id: GuidGenerator.Create(), productId: orderItem.productId, productName: orderItem.productName, productCode: orderItem.productCode, @@ -92,7 +99,8 @@ public class OrderManager : DomainService .WithData("OrderId", orderId); } - //Update order.PaymentMethodToken + //Update order.PaymentId + //Update order.PaymentStatus order.SetOrderPaid(); return await _orderRepository.UpdateAsync(order); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs index 8c1ed97e..3d24451d 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs @@ -66,6 +66,7 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore b.Property("_orderStatusId").UsePropertyAccessMode(PropertyAccessMode.Field) .HasColumnName("OrderStatusId") .IsRequired(); + b.Property(q => q.PaymentStatus).HasMaxLength(OrderConstants.PaymentStatusMaxLength); b.HasOne().WithMany().HasForeignKey(q => q.BuyerId).IsRequired(false); b.HasOne(q => q.OrderStatus).WithMany().HasForeignKey("_orderStatusId"); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104093641_Added_Order_PaymentRequest_Info.Designer.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104093641_Added_Order_PaymentRequest_Info.Designer.cs new file mode 100644 index 00000000..d2571549 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104093641_Added_Order_PaymentRequest_Info.Designer.cs @@ -0,0 +1,248 @@ +// +using System; +using EShopOnAbp.OrderingService.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Volo.Abp.EntityFrameworkCore; + +#nullable disable + +namespace EShopOnAbp.OrderingService.Migrations +{ + [DbContext(typeof(OrderingServiceDbContext))] + [Migration("20220104093641_Added_Order_PaymentRequest_Info")] + partial class Added_Order_PaymentRequest_Info + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql) + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Buyers.Buyer", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("character varying(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("ExtraProperties") + .HasColumnType("text") + .HasColumnName("ExtraProperties"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("_paymentTypeId") + .HasColumnType("integer") + .HasColumnName("PaymentTypeId"); + + b.HasKey("Id"); + + b.HasIndex("_paymentTypeId"); + + b.ToTable("Buyers", (string)null); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Buyers.PaymentType", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasDefaultValue(1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.HasKey("Id"); + + b.ToTable("PaymentTypes", (string)null); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("BuyerId") + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("character varying(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("ExtraProperties") + .HasColumnType("text") + .HasColumnName("ExtraProperties"); + + b.Property("OrderDate") + .HasColumnType("timestamp with time zone"); + + b.Property("PaymentRequestId") + .HasColumnType("uuid"); + + b.Property("PaymentStatus") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("_orderStatusId") + .HasColumnType("integer") + .HasColumnName("OrderStatusId"); + + b.HasKey("Id"); + + b.HasIndex("BuyerId"); + + b.HasIndex("Id"); + + b.HasIndex("_orderStatusId"); + + b.ToTable("Orders", (string)null); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("Discount") + .HasColumnType("numeric"); + + b.Property("OrderId") + .HasColumnType("uuid"); + + b.Property("PictureUrl") + .HasColumnType("text"); + + b.Property("ProductCode") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("UnitPrice") + .HasColumnType("numeric"); + + b.Property("Units") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems", (string)null); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderStatus", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasDefaultValue(1); + + b.Property("Name") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.ToTable("OrderStatus", (string)null); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Buyers.Buyer", b => + { + b.HasOne("EShopOnAbp.OrderingService.Buyers.PaymentType", "PaymentType") + .WithMany() + .HasForeignKey("_paymentTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PaymentType"); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => + { + b.HasOne("EShopOnAbp.OrderingService.Buyers.Buyer", null) + .WithMany() + .HasForeignKey("BuyerId"); + + b.HasOne("EShopOnAbp.OrderingService.Orders.OrderStatus", "OrderStatus") + .WithMany() + .HasForeignKey("_orderStatusId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("EShopOnAbp.OrderingService.Orders.Address", "Address", b1 => + { + b1.Property("OrderId") + .HasColumnType("uuid"); + + b1.Property("City") + .HasColumnType("text"); + + b1.Property("Country") + .HasColumnType("text"); + + b1.Property("Description") + .HasColumnType("text"); + + b1.Property("Street") + .HasColumnType("text"); + + b1.Property("ZipCode") + .HasColumnType("text"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + + b.Navigation("Address"); + + b.Navigation("OrderStatus"); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => + { + b.HasOne("EShopOnAbp.OrderingService.Orders.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => + { + b.Navigation("OrderItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104093641_Added_Order_PaymentRequest_Info.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104093641_Added_Order_PaymentRequest_Info.cs new file mode 100644 index 00000000..fd25fd3d --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104093641_Added_Order_PaymentRequest_Info.cs @@ -0,0 +1,47 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EShopOnAbp.OrderingService.Migrations +{ + public partial class Added_Order_PaymentRequest_Info : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "PaymentMethodToken", + table: "Orders"); + + migrationBuilder.AddColumn( + name: "PaymentRequestId", + table: "Orders", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "PaymentStatus", + table: "Orders", + type: "character varying(256)", + maxLength: 256, + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "PaymentRequestId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "PaymentStatus", + table: "Orders"); + + migrationBuilder.AddColumn( + name: "PaymentMethodToken", + table: "Orders", + type: "text", + nullable: true); + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs index fa6c25fa..3d7badcc 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -95,8 +95,12 @@ namespace EShopOnAbp.OrderingService.Migrations b.Property("OrderDate") .HasColumnType("timestamp with time zone"); - b.Property("PaymentMethodToken") - .HasColumnType("text"); + b.Property("PaymentRequestId") + .HasColumnType("uuid"); + + b.Property("PaymentStatus") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); b.Property("_orderStatusId") .HasColumnType("integer")