From 7fb9831a1ba8c85b5d7e9ff9541b99ccaadde9dd Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 12:50:13 +0300 Subject: [PATCH 01/24] Added payment type to buyer --- .../Localization/OrderingService/en.json | 1 + .../Localization/OrderingService/tr.json | 1 + .../OrderingServiceErrorCodes.cs | 1 + .../Buyers/Buyer.cs | 15 ++++-- .../Buyers/PaymentType.cs | 47 +++++++++++++++++++ 5 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json index b4ba5394..84aad32a 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json @@ -4,6 +4,7 @@ "MyAccount": "My account", "SamplePageMessage": "A sample page for the OrderingService module", "Ordering:00001": "Possible values for Order status: {0}", + "Ordering:00011": "Possible values for Payment types: {0}", "Ordering:00002": "Invalid number of units", "Ordering:00003": "Invalid discount", "Ordering:00004": "The total of order item is lower than applied discount" diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json index eadfdc27..14f3eea7 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json @@ -4,6 +4,7 @@ "MyAccount": "Hesabım", "SamplePageMessage": "OrderingService modulünden örnek bir sayfa", "Ordering:00001": "Muhtemel Sipariş durum değerleri: {0}", + "Ordering:00011": "Muhtemel Ödeme türleri: {0}", "Ordering:00002": "Ürün adedi negatif olamaz", "Ordering:00003": "Geçersiz indirim", "Ordering:00004": "Ürünlerin toplam bedeli, uygulanan indirimden daha az olamaz" diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs index b520db67..f4ab7c19 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs @@ -3,6 +3,7 @@ public static class OrderingServiceErrorCodes { public const string OrderingStatusNotFound = "Ordering:00001"; + public const string PaymentTypeNotFound = "Ordering:00011"; public const string InvalidUnits = "Ordering:00002"; public const string InvalidDiscount = "Ordering:00003"; public const string InvalidTotalForDiscount = "Ordering:00004"; diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs index d6727646..624ed456 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs @@ -7,18 +7,23 @@ namespace EShopOnAbp.OrderingService.Buyers; public class Buyer : AggregateRoot { - public string UserName { get; private set; } + private int _paymentTypeId; public string Name { get; private set; } - public string PaymentId { get; private set; } + public string Email { get; private set; } + public PaymentType PaymentType { get; private set; } private Buyer() { } - public Buyer(Guid id, [NotNull] string userName, [NotNull] string name, [NotNull] string paymentId) : base(id) + public Buyer(Guid id, + [NotNull] string userName, + [NotNull] string name, + [NotNull] string email, + PaymentType paymentType) : base(id) { - UserName = Check.NotNullOrEmpty(userName, nameof(userName)); + _paymentTypeId = PaymentType.FromName(paymentType.Name).Id; Name = Check.NotNullOrEmpty(name, nameof(name)); - PaymentId = Check.NotNullOrEmpty(paymentId, nameof(paymentId)); + Email = Check.NotNullOrEmpty(email, nameof(email)); } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs new file mode 100644 index 00000000..afd15501 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Volo.Abp; + +namespace EShopOnAbp.OrderingService.Buyers; + +public class PaymentType : Enumeration +{ + public static PaymentType Paypal = new PaymentType(1, nameof(Paypal).ToLowerInvariant()); + public static PaymentType Visa = new PaymentType(1, nameof(Visa).ToLowerInvariant()); + public static PaymentType MasterCard = new PaymentType(1, nameof(MasterCard).ToLowerInvariant()); + + public PaymentType(int id, string name) : base(id, name) + { + } + + public static IEnumerable List() => + new[] {Paypal, Visa, Visa, MasterCard}; + + public static PaymentType FromName(string name) + { + var state = List() + .SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); + + if (state == null) + { + throw new BusinessException(OrderingServiceErrorCodes.PaymentTypeNotFound) + .WithData("PaymentType", String.Join(",", List().Select(s => s.Name))); + } + + return state; + } + + public static PaymentType From(int id) + { + var state = List().SingleOrDefault(s => s.Id == id); + + if (state == null) + { + throw new BusinessException(OrderingServiceErrorCodes.PaymentTypeNotFound) + .WithData("PaymentType", String.Join(",", List().Select(s => s.Name))); + } + + return state; + } +} \ No newline at end of file From 928eb64ea601c1c48e87c8e4e4c50672107a1aa7 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 12:51:09 +0300 Subject: [PATCH 02/24] updated order status --- .../src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs | 7 +++---- .../Orders/OrderStatus.cs | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs index 3867875a..fe94679e 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -10,8 +10,7 @@ public class Order : AggregateRoot private int _orderStatusId; public DateTime OrderDate { get; private set; } public Guid? BuyerId { get; private set; } - public string Description { get; private set; } - public string PaymentMethodToken { get; private set; } // PaymentId or token for validation + public string PaymentMethodToken { get; private set; } // Payment token for validation public Address Address { get; private set; } public OrderStatus OrderStatus { get; private set; } public List OrderItems { get; private set; } @@ -20,9 +19,9 @@ public class Order : AggregateRoot { } - public Order(Guid id, Address address, Guid? buyerId = null, string paymentMethodToken = null) : base() + internal Order(Guid id, Address address, Guid? buyerId = null, string paymentMethodToken = null) : base() { - _orderStatusId = OrderStatus.Submitted.Id; + _orderStatusId = OrderStatus.Placed.Id; OrderDate = DateTime.UtcNow; Address = address; BuyerId = buyerId; diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs index 676fe3ae..d6536fbd 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs @@ -7,7 +7,7 @@ namespace EShopOnAbp.OrderingService.Orders; public class OrderStatus: Enumeration { - public static OrderStatus Submitted = new OrderStatus(1, nameof(Submitted).ToLowerInvariant()); + public static OrderStatus Placed = new OrderStatus(1, nameof(Placed).ToLowerInvariant()); public static OrderStatus AwaitingValidation = new OrderStatus(2, nameof(AwaitingValidation).ToLowerInvariant()); public static OrderStatus StockConfirmed = new OrderStatus(3, nameof(StockConfirmed).ToLowerInvariant()); public static OrderStatus Paid = new OrderStatus(4, nameof(Paid).ToLowerInvariant()); @@ -20,7 +20,7 @@ public class OrderStatus: Enumeration } public static IEnumerable List() => - new[] { Submitted, AwaitingValidation, StockConfirmed, Paid, Shipped, Cancelled }; + new[] { Placed, AwaitingValidation, StockConfirmed, Paid, Shipped, Cancelled }; public static OrderStatus FromName(string name) { From af1ad3c3e5f8f205d2e265cf13af2de3bcdcedf9 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 12:51:27 +0300 Subject: [PATCH 03/24] Added payment data seeding --- .../OrderServiceDataSeedContributor.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderServiceDataSeedContributor.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderServiceDataSeedContributor.cs index a49ba8df..468aca95 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderServiceDataSeedContributor.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderServiceDataSeedContributor.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using EShopOnAbp.OrderingService.Buyers; using EShopOnAbp.OrderingService.Orders; using Microsoft.EntityFrameworkCore; using Volo.Abp.Data; @@ -24,27 +25,24 @@ public class OrderServiceDataSeedContributor : IDataSeedContributor, ITransientD public async Task SeedAsync(DataSeedContext context) { await SeedOrderStatusAsync(); + await SeedPaymentTypesAsync(); } - private async Task SeedOrderStatusAsync() + private async Task SeedPaymentTypesAsync() { - if (!await _dbContext.Set().AnyAsync()) + if (!await _dbContext.Set().AnyAsync()) { - _dbContext.Set().AddRange(GetOrderStatusList()); + await _dbContext.Set().AddRangeAsync(PaymentType.List()); await _dbContext.SaveChangesAsync(); } } - private List GetOrderStatusList() + private async Task SeedOrderStatusAsync() { - return new List + if (!await _dbContext.Set().AnyAsync()) { - OrderStatus.Submitted, - OrderStatus.AwaitingValidation, - OrderStatus.StockConfirmed, - OrderStatus.Paid, - OrderStatus.Shipped, - OrderStatus.Cancelled - }; + await _dbContext.Set().AddRangeAsync(OrderStatus.List()); + await _dbContext.SaveChangesAsync(); + } } } \ No newline at end of file From 570e945008ada4b9eab2842c414402e9e40d94a0 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 12:52:03 +0300 Subject: [PATCH 04/24] updated order and buyer migration --- .../OrderingServiceDbContext.cs | 27 +- ...094501_Updated-Order-and-Buyer.Designer.cs | 240 ++++++++++++++++++ .../20211231094501_Updated-Order-and-Buyer.cs | 94 +++++++ .../OrderingServiceDbContextModelSnapshot.cs | 45 +++- .../Orders/EfCoreOrderRepository.cs | 13 + 5 files changed, 405 insertions(+), 14 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231094501_Updated-Order-and-Buyer.Designer.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231094501_Updated-Order-and-Buyer.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs index afef93c7..db163a01 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs @@ -33,9 +33,29 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "Buyers", OrderingServiceDbProperties.DbSchema); b.ConfigureByConvention(); //auto configure for the base class props - b.Property(q => q.UserName).IsRequired(); + b.Property(q => q.Email).IsRequired(); b.Property(q => q.Name).IsRequired(); - b.Property(q => q.PaymentId).IsRequired(); + + b.Property("_paymentTypeId").UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("PaymentTypeId") + .IsRequired(); + + b.HasOne(q => q.PaymentType).WithMany().HasForeignKey("_paymentTypeId"); + }); + builder.Entity(b => + { + b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "PaymentTypes", + OrderingServiceDbProperties.DbSchema); + b.ConfigureByConvention(); //auto configure for the base class props + + b.HasKey(q => q.Id); + b.Property(q => q.Id) + .HasDefaultValue(1) + .ValueGeneratedNever() + .IsRequired(); + b.Property(o => o.Name) + .HasMaxLength(OrderConstants.OrderPaymentTypeNameMaxLength) + .IsRequired(); }); builder.Entity(b => @@ -46,7 +66,6 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore b.Property("_orderStatusId").UsePropertyAccessMode(PropertyAccessMode.Field) .HasColumnName("OrderStatusId") .IsRequired(); - b.Property(q => q.Description).HasMaxLength(OrderConstants.OrderDescriptionMaxLength).IsRequired(false); b.HasOne().WithMany().HasForeignKey(q => q.BuyerId).IsRequired(false); b.HasOne(q => q.OrderStatus).WithMany().HasForeignKey("_orderStatusId"); @@ -56,7 +75,7 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore b.HasIndex(q => q.Id); b.HasIndex(q => q.BuyerId); }); - // Consider removing persistancy to db or seeding + builder.Entity(b => { b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "OrderStatus", diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231094501_Updated-Order-and-Buyer.Designer.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231094501_Updated-Order-and-Buyer.Designer.cs new file mode 100644 index 00000000..07c6ca36 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231094501_Updated-Order-and-Buyer.Designer.cs @@ -0,0 +1,240 @@ +// +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("20211231094501_Updated-Order-and-Buyer")] + partial class UpdatedOrderandBuyer + { + 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("PaymentMethodToken") + .HasColumnType("text"); + + 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("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/20211231094501_Updated-Order-and-Buyer.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231094501_Updated-Order-and-Buyer.cs new file mode 100644 index 00000000..8e0d8f06 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231094501_Updated-Order-and-Buyer.cs @@ -0,0 +1,94 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EShopOnAbp.OrderingService.Migrations +{ + public partial class UpdatedOrderandBuyer : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Description", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "PaymentId", + table: "Buyers"); + + migrationBuilder.RenameColumn( + name: "UserName", + table: "Buyers", + newName: "Email"); + + migrationBuilder.AddColumn( + name: "PaymentTypeId", + table: "Buyers", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "PaymentTypes", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false, defaultValue: 1), + Name = table.Column(type: "character varying(128)", maxLength: 128, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PaymentTypes", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Buyers_PaymentTypeId", + table: "Buyers", + column: "PaymentTypeId"); + + migrationBuilder.AddForeignKey( + name: "FK_Buyers_PaymentTypes_PaymentTypeId", + table: "Buyers", + column: "PaymentTypeId", + principalTable: "PaymentTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Buyers_PaymentTypes_PaymentTypeId", + table: "Buyers"); + + migrationBuilder.DropTable( + name: "PaymentTypes"); + + migrationBuilder.DropIndex( + name: "IX_Buyers_PaymentTypeId", + table: "Buyers"); + + migrationBuilder.DropColumn( + name: "PaymentTypeId", + table: "Buyers"); + + migrationBuilder.RenameColumn( + name: "Email", + table: "Buyers", + newName: "UserName"); + + migrationBuilder.AddColumn( + name: "Description", + table: "Orders", + type: "character varying(1024)", + maxLength: 1024, + nullable: true); + + migrationBuilder.AddColumn( + name: "PaymentId", + table: "Buyers", + type: "text", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs index 14f7bd8a..02fb559b 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -35,6 +35,10 @@ namespace EShopOnAbp.OrderingService.Migrations .HasColumnType("character varying(40)") .HasColumnName("ConcurrencyStamp"); + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + b.Property("ExtraProperties") .HasColumnType("text") .HasColumnName("ExtraProperties"); @@ -43,17 +47,31 @@ namespace EShopOnAbp.OrderingService.Migrations .IsRequired() .HasColumnType("text"); - b.Property("PaymentId") - .IsRequired() - .HasColumnType("text"); + b.Property("_paymentTypeId") + .HasColumnType("integer") + .HasColumnName("PaymentTypeId"); + + b.HasKey("Id"); - b.Property("UserName") + 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() - .HasColumnType("text"); + .HasMaxLength(128) + .HasColumnType("character varying(128)"); b.HasKey("Id"); - b.ToTable("Buyers", (string)null); + b.ToTable("PaymentTypes", (string)null); }); modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => @@ -70,10 +88,6 @@ namespace EShopOnAbp.OrderingService.Migrations .HasColumnType("character varying(40)") .HasColumnName("ConcurrencyStamp"); - b.Property("Description") - .HasMaxLength(1024) - .HasColumnType("character varying(1024)"); - b.Property("ExtraProperties") .HasColumnType("text") .HasColumnName("ExtraProperties"); @@ -149,6 +163,17 @@ namespace EShopOnAbp.OrderingService.Migrations 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) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs new file mode 100644 index 00000000..a1b3ec37 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs @@ -0,0 +1,13 @@ +using System; +using EShopOnAbp.OrderingService.EntityFrameworkCore; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace EShopOnAbp.OrderingService.Orders; + +public class EfCoreOrderRepository : EfCoreRepository, IOrderRepository +{ + public EfCoreOrderRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) + { + } +} \ No newline at end of file From ce501440e07938dadd43a504d2e15ce88b199262 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 15:30:22 +0300 Subject: [PATCH 05/24] fixed order id setting error --- .../src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs index fe94679e..561aa14e 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -19,7 +19,7 @@ public class Order : AggregateRoot { } - internal Order(Guid id, Address address, Guid? buyerId = null, string paymentMethodToken = null) : base() + internal Order(Guid id, Address address, Guid? buyerId = null, string paymentMethodToken = null) : base(id) { _orderStatusId = OrderStatus.Placed.Id; OrderDate = DateTime.UtcNow; From 6eabc94608872dcbda525dd040ed7d352d7392ba Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 15:31:30 +0300 Subject: [PATCH 06/24] added buyer repository --- .../Buyers/Buyer.cs | 3 +-- .../Buyers/IBuyerRepository.cs | 8 ++++++++ .../Buyers/EfCoreBuyerRepository.cs | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/IBuyerRepository.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs index 624ed456..6ab142e4 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs @@ -16,8 +16,7 @@ public class Buyer : AggregateRoot { } - public Buyer(Guid id, - [NotNull] string userName, + internal Buyer(Guid id, [NotNull] string name, [NotNull] string email, PaymentType paymentType) : base(id) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/IBuyerRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/IBuyerRepository.cs new file mode 100644 index 00000000..1746b2f7 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/IBuyerRepository.cs @@ -0,0 +1,8 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace EShopOnAbp.OrderingService.Buyers; + +public interface IBuyerRepository : IRepository +{ +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs new file mode 100644 index 00000000..8e0760d1 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs @@ -0,0 +1,14 @@ +using System; +using EShopOnAbp.OrderingService.EntityFrameworkCore; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace EShopOnAbp.OrderingService.Buyers; + +public class EfCoreBuyerRepository : EfCoreRepository, IBuyerRepository +{ + public EfCoreBuyerRepository(IDbContextProvider dbContextProvider) : base( + dbContextProvider) + { + } +} \ No newline at end of file From bb07bc02398d54ef6c4c47ff519d61a3b68b1946 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 15:33:02 +0300 Subject: [PATCH 07/24] added OrderManager --- .../Orders/OrderConstants.cs | 2 +- .../Orders/Address.cs | 13 ++-- .../Orders/IOrderRepository.cs | 8 +++ .../Orders/OrderManager.cs | 65 +++++++++++++++++++ 4 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.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 1cff526c..7a01ed08 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs @@ -2,6 +2,6 @@ public static class OrderConstants { - public const int OrderDescriptionMaxLength = 1024; + public const int OrderPaymentTypeNameMaxLength = 128; public const int OrderStatusNameMaxLength = 256; } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Address.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Address.cs index 1de9d0fb..21d2e2f7 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Address.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Address.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Volo.Abp; using Volo.Abp.Domain.Values; namespace EShopOnAbp.OrderingService.Orders; @@ -15,21 +16,21 @@ public class Address : ValueObject { } - public Address(string street, string city, string description, string country, string zipcode) + public Address(string street, string city, string country, string zipcode, string description) { - Street = street; - City = city; + Street = Check.NotNullOrEmpty(street, nameof(street)); + City = Check.NotNullOrEmpty(city, nameof(city)); + Country = Check.NotNullOrEmpty(country, nameof(country)); + ZipCode = Check.NotNullOrEmpty(zipcode, nameof(zipcode)); Description = description; - Country = country; - ZipCode = zipcode; } protected override IEnumerable GetAtomicValues() { yield return Street; yield return City; - yield return Description; yield return Country; yield return ZipCode; + yield return Description; } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs new file mode 100644 index 00000000..65c20d35 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs @@ -0,0 +1,8 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace EShopOnAbp.OrderingService.Orders; + +public interface IOrderRepository : IRepository +{ +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs new file mode 100644 index 00000000..3cf3aed6 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using EShopOnAbp.OrderingService.Buyers; +using Volo.Abp.Domain.Services; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderManager : DomainService +{ + private readonly IOrderRepository _orderRepository; + private readonly IBuyerRepository _buyerRepository; + + public OrderManager(IOrderRepository orderRepository, IBuyerRepository buyerRepository) + { + _orderRepository = orderRepository; + _buyerRepository = buyerRepository; + } + + public async Task CreateOrderAsync( + int paymentTypeId, + string buyerName, + string buyerEmail, + List<(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units)> + orderItems, + string addressStreet, + string addressCity, + string addressCountry, + string addressZipCode, + string addressDescription = null + ) + { + // Create buyer + Buyer buyer = await _buyerRepository.InsertAsync( + new Buyer(GuidGenerator.Create(), buyerName, buyerEmail, PaymentType.From(paymentTypeId)), + autoSave: true + ); + + // Create new order + Order order = new Order( + id: GuidGenerator.Create(), + address: new Address(street: addressStreet, + city: addressCity, + country: addressCountry, + zipcode: addressZipCode, + description: addressDescription), + buyerId: buyer.Id + ); + + // Add new order items + foreach (var orderItem in orderItems) + { + order.AddOrderItem( + productId: orderItem.productId, + productName: orderItem.productName, + unitPrice: orderItem.unitPrice, + discount: orderItem.discount, + pictureUrl: orderItem.pictureUrl, + units: orderItem.units + ); + } + + return await _orderRepository.InsertAsync(order); + } +} \ No newline at end of file From 041f9665d22f5b504059e2da8adc5629bf493c38 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 15:33:20 +0300 Subject: [PATCH 08/24] added order appservice --- .../Buyers/BuyerDto.cs | 12 +++ .../Orders/IOrderAppService.cs | 11 +++ .../Orders/OrderAddressDto.cs | 12 +++ .../Orders/OrderCreateDto.cs | 10 +++ .../Orders/OrderDto.cs | 16 ++++ .../Orders/OrderItemCreateDto.cs | 13 +++ .../Orders/OrderItemDto.cs | 14 ++++ .../OrderingServiceAppService.cs | 14 ---- ...ringServiceApplicationAutoMapperProfile.cs | 17 +++- .../Orders/OrderAppService.cs | 82 +++++++++++++++++++ 10 files changed, 184 insertions(+), 17 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Buyers/BuyerDto.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderAddressDto.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderCreateDto.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemDto.cs delete mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceAppService.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Buyers/BuyerDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Buyers/BuyerDto.cs new file mode 100644 index 00000000..e8e8b56d --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Buyers/BuyerDto.cs @@ -0,0 +1,12 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace EShopOnAbp.OrderingService.Buyers; + +public class BuyerDto : EntityDto +{ + public string Name { get; set; } + public string Email { get; set; } + public string PaymentType { get; set; } + public int PaymentTypeId { get; set; } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs new file mode 100644 index 00000000..cf232c60 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs @@ -0,0 +1,11 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; + +namespace EShopOnAbp.OrderingService.Orders; + +public interface IOrderAppService : IApplicationService +{ + Task CreateAsync(OrderCreateDto input); + Task GetAsync(Guid id); +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderAddressDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderAddressDto.cs new file mode 100644 index 00000000..6dd08819 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderAddressDto.cs @@ -0,0 +1,12 @@ +using System.ComponentModel.DataAnnotations; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderAddressDto +{ + public string Description { get; set; } + [Required]public string Street { get; set; } + [Required]public string City { get; set; } + [Required]public string Country { get; set; } + [Required]public string ZipCode { get; set; } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderCreateDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderCreateDto.cs new file mode 100644 index 00000000..8c1149d7 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderCreateDto.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderCreateDto +{ + public int PaymentTypeId { get; set; } + public OrderAddressDto Address { get; set; } = new(); + public List Products { get; set; } = new(); +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs new file mode 100644 index 00000000..7b0145e3 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using EShopOnAbp.OrderingService.Buyers; +using Volo.Abp.Application.Dtos; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderDto : EntityDto +{ + public DateTime OrderDate { get; set; } + public int OrderStatusId { get; set; } + public string OrderStatus { get; set; } + public BuyerDto Buyer { get; set; } + public OrderAddressDto Address { get; set; } = new(); + public List Products { get; set; } = new(); +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs new file mode 100644 index 00000000..5bb57765 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs @@ -0,0 +1,13 @@ +using System; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderItemCreateDto +{ + public Guid ProductId { get; set; } + public string ProductName { get; set; } + public string PictureUrl { get; set; } + public decimal UnitPrice { get; set; } + public decimal Discount { get; set; } + public int Units { get; set; } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemDto.cs new file mode 100644 index 00000000..53d0e849 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemDto.cs @@ -0,0 +1,14 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderItemDto : EntityDto +{ + public Guid ProductId { get; set; } + public string ProductName { get; set; } + public string PictureUrl { get; set; } + public decimal UnitPrice { get; set; } + public decimal Discount { get; set; } + public int Units { get; set; } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceAppService.cs deleted file mode 100644 index 3234e0be..00000000 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceAppService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using EShopOnAbp.OrderingService.Localization; -using Volo.Abp.Application.Services; - -namespace EShopOnAbp.OrderingService -{ - public abstract class OrderingServiceAppService : ApplicationService - { - protected OrderingServiceAppService() - { - LocalizationResource = typeof(OrderingServiceResource); - ObjectMapperContext = typeof(OrderingServiceApplicationModule); - } - } -} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs index 965a1899..3247f98a 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs @@ -1,4 +1,7 @@ using AutoMapper; +using EShopOnAbp.OrderingService.Buyers; +using EShopOnAbp.OrderingService.Orders; +using Volo.Abp.AutoMapper; namespace EShopOnAbp.OrderingService { @@ -6,9 +9,17 @@ namespace EShopOnAbp.OrderingService { public OrderingServiceApplicationAutoMapperProfile() { - /* You can configure your AutoMapper mapping configuration here. - * Alternatively, you can split your mapping configurations - * into multiple profile classes for a better organization. */ + CreateMap(); + + CreateMap(); + CreateMap() + .ForMember(q => q.PaymentType, opt => opt.MapFrom(q => q.PaymentType.Name)) + .ForMember(q => q.PaymentTypeId, opt => opt.MapFrom(q => q.PaymentType.Id)); + + CreateMap() + .Ignore(q => q.Address) + .Ignore(q => q.Products) + .Ignore(q => q.Buyer); } } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs new file mode 100644 index 00000000..ceb76211 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using EShopOnAbp.OrderingService.Buyers; +using EShopOnAbp.OrderingService.Localization; +using Volo.Abp.Application.Services; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderAppService : ApplicationService, IOrderAppService +{ + private readonly OrderManager _orderManager; + private readonly IOrderRepository _orderRepository; + private readonly IBuyerRepository _buyerRepository; + + public OrderAppService(OrderManager orderManager, + IOrderRepository orderRepository, + IBuyerRepository buyerRepository) + { + _orderManager = orderManager; + _orderRepository = orderRepository; + _buyerRepository = buyerRepository; + LocalizationResource = typeof(OrderingServiceResource); + ObjectMapperContext = typeof(OrderingServiceApplicationModule); + } + + public async Task GetAsync(Guid id) + { + var order = await _orderRepository.GetAsync(id); + return await CreateOrderDtoMappingAsync(order); + } + + public async Task CreateAsync(OrderCreateDto input) + { + var orderItems = GetProductListTuple(input.Products); + + var placedOrder = await _orderManager.CreateOrderAsync + ( + paymentTypeId: input.PaymentTypeId, + buyerName: CurrentUser.Name, + buyerEmail: CurrentUser.Email, + orderItems: orderItems, + addressStreet: input.Address.Street, + addressCity: input.Address.City, + addressCountry: input.Address.Country, + addressZipCode: input.Address.ZipCode, + addressDescription: input.Address.Description + ); + + return await CreateOrderDtoMappingAsync(placedOrder); + } + + private List<(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units + )> GetProductListTuple(List products) + { + var orderItems = + new List<(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int + units)>(); + foreach (var product in products) + { + orderItems.Add((product.ProductId, product.ProductName, product.UnitPrice, product.Discount, + product.PictureUrl, product.Units)); + } + + return orderItems; + } + + private async Task CreateOrderDtoMappingAsync(Order placedOrder) + { + var buyer = await _buyerRepository.GetAsync(placedOrder.BuyerId.GetValueOrDefault()); + return new OrderDto() + { + Address = ObjectMapper.Map(placedOrder.Address), + Products = ObjectMapper.Map, List>(placedOrder.OrderItems), + Buyer = ObjectMapper.Map(buyer), + Id = placedOrder.Id, + OrderDate = placedOrder.OrderDate, + OrderStatus = placedOrder.OrderStatus.Name, + OrderStatusId = placedOrder.OrderStatus.Id + }; + } +} \ No newline at end of file From 260bb7703717b258b9a0476ea1dfd4d49152e552 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 16:37:17 +0300 Subject: [PATCH 09/24] generated OrderService proxy --- .../OrderingServiceRemoteServiceConsts.cs | 2 +- .../OrderClientProxy.Generated.cs | 34 ++++++ .../ClientProxies/OrderClientProxy.cs | 8 ++ .../Ordering-generate-proxy.json | 106 ++++++++++++++++++ .../OrderingServiceHttpApiClientModule.cs | 5 +- .../OrderingServiceHttpApiHostModule.cs | 12 +- 6 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/Ordering-generate-proxy.json diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderingServiceRemoteServiceConsts.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderingServiceRemoteServiceConsts.cs index 6d7a1e67..ca7531ee 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderingServiceRemoteServiceConsts.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/OrderingServiceRemoteServiceConsts.cs @@ -2,6 +2,6 @@ { public class OrderingServiceRemoteServiceConsts { - public const string RemoteServiceName = "OrderingService"; + public const string RemoteServiceName = "Ordering"; } } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs new file mode 100644 index 00000000..41dd6783 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.Generated.cs @@ -0,0 +1,34 @@ +// This file is automatically generated by ABP framework to use MVC Controllers from CSharp +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Http.Client; +using Volo.Abp.Http.Modeling; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.ClientProxying; +using EShopOnAbp.OrderingService.Orders; + +// ReSharper disable once CheckNamespace +namespace EShopOnAbp.OrderingService.Orders.ClientProxies +{ + [Dependency(ReplaceServices = true)] + [ExposeServices(typeof(IOrderAppService), typeof(OrderClientProxy))] + public partial class OrderClientProxy : ClientProxyBase, IOrderAppService + { + public virtual async Task GetAsync(Guid id) + { + return await RequestAsync(nameof(GetAsync), new ClientProxyRequestTypeValue + { + { typeof(Guid), id } + }); + } + + public virtual async Task CreateAsync(OrderCreateDto input) + { + return await RequestAsync(nameof(CreateAsync), new ClientProxyRequestTypeValue + { + { typeof(OrderCreateDto), input } + }); + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.cs new file mode 100644 index 00000000..af3b463e --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderClientProxy.cs @@ -0,0 +1,8 @@ +// This file is part of OrderClientProxy, you can customize it here +// ReSharper disable once CheckNamespace +namespace EShopOnAbp.OrderingService.Orders.ClientProxies +{ + public partial class OrderClientProxy + { + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/Ordering-generate-proxy.json b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/Ordering-generate-proxy.json new file mode 100644 index 00000000..2d618d12 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/Ordering-generate-proxy.json @@ -0,0 +1,106 @@ +{ + "modules": { + "ordering": { + "rootPath": "ordering", + "remoteServiceName": "Ordering", + "controllers": { + "EShopOnAbp.OrderingService.Orders.OrderAppService": { + "controllerName": "Order", + "controllerGroupName": "Order", + "type": "EShopOnAbp.OrderingService.Orders.OrderAppService", + "interfaces": [ + { + "type": "Volo.Abp.Validation.IValidationEnabled" + }, + { + "type": "Volo.Abp.Auditing.IAuditingEnabled" + }, + { + "type": "Volo.Abp.GlobalFeatures.IGlobalFeatureCheckingEnabled" + }, + { + "type": "EShopOnAbp.OrderingService.Orders.IOrderAppService" + } + ], + "actions": { + "GetAsyncById": { + "uniqueName": "GetAsyncById", + "name": "GetAsync", + "httpMethod": "GET", + "url": "api/ordering/order/{id}", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "id", + "typeAsString": "System.Guid, System.Private.CoreLib", + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "id", + "name": "id", + "jsonName": null, + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": [], + "bindingSourceId": "Path", + "descriptorName": "" + } + ], + "returnValue": { + "type": "EShopOnAbp.OrderingService.Orders.OrderDto", + "typeSimple": "EShopOnAbp.OrderingService.Orders.OrderDto" + }, + "allowAnonymous": null, + "implementFrom": "EShopOnAbp.OrderingService.Orders.IOrderAppService" + }, + "CreateAsyncByInput": { + "uniqueName": "CreateAsyncByInput", + "name": "CreateAsync", + "httpMethod": "POST", + "url": "api/ordering/order", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "input", + "typeAsString": "EShopOnAbp.OrderingService.Orders.OrderCreateDto, EShopOnAbp.OrderingService.Application.Contracts", + "type": "EShopOnAbp.OrderingService.Orders.OrderCreateDto", + "typeSimple": "EShopOnAbp.OrderingService.Orders.OrderCreateDto", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "input", + "name": "input", + "jsonName": null, + "type": "EShopOnAbp.OrderingService.Orders.OrderCreateDto", + "typeSimple": "EShopOnAbp.OrderingService.Orders.OrderCreateDto", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "Body", + "descriptorName": "" + } + ], + "returnValue": { + "type": "EShopOnAbp.OrderingService.Orders.OrderDto", + "typeSimple": "EShopOnAbp.OrderingService.Orders.OrderDto" + }, + "allowAnonymous": null, + "implementFrom": "EShopOnAbp.OrderingService.Orders.IOrderAppService" + } + } + } + } + } + }, + "types": {} +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/OrderingServiceHttpApiClientModule.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/OrderingServiceHttpApiClientModule.cs index 1b403c26..e52daa5c 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/OrderingServiceHttpApiClientModule.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/OrderingServiceHttpApiClientModule.cs @@ -12,7 +12,7 @@ namespace EShopOnAbp.OrderingService { public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddStaticHttpClientProxies( + context.Services.AddHttpClientProxies( typeof(OrderingServiceApplicationContractsModule).Assembly, OrderingServiceRemoteServiceConsts.RemoteServiceName ); @@ -21,7 +21,6 @@ namespace EShopOnAbp.OrderingService { options.FileSets.AddEmbedded(); }); - } } -} +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs index 6e89ade8..41d0ba31 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; using System.Linq; using Volo.Abp; +using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Modularity; using Volo.Abp.Threading; @@ -30,7 +31,6 @@ namespace EShopOnAbp.OrderingService var configuration = context.Services.GetConfiguration(); JwtBearerConfigurationHelper.Configure(context, "OrderingService"); - // SwaggerConfigurationHelper.Configure(context, "Catalog Service API"); SwaggerWithAuthConfigurationHelper.Configure( context: context, @@ -60,6 +60,16 @@ namespace EShopOnAbp.OrderingService .AllowCredentials(); }); }); + + // TODO: Crate controller instead of auto-controller configuration + Configure(options => + { + options.ConventionalControllers.Create(typeof(OrderingServiceApplicationModule).Assembly, opts => + { + opts.RootPath = OrderingServiceRemoteServiceConsts.RemoteServiceName.ToLowerInvariant(); + opts.RemoteServiceName = OrderingServiceRemoteServiceConsts.RemoteServiceName; + }); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) From e33a4b039d605dd272e5a1d3c4b87fd0d945cde2 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 17:02:09 +0300 Subject: [PATCH 10/24] added ProductCode --- .../Orders/Order.cs | 6 +- .../Orders/OrderItem.cs | 4 +- .../Orders/OrderManager.cs | 4 +- .../OrderingServiceDbContext.cs | 1 + ...211231135901_Added-ProductCode.Designer.cs | 244 ++++++++++++++++++ .../20211231135901_Added-ProductCode.cs | 26 ++ .../OrderingServiceDbContextModelSnapshot.cs | 4 + 7 files changed, 284 insertions(+), 5 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231135901_Added-ProductCode.Designer.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231135901_Added-ProductCode.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs index 561aa14e..6086847d 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -29,8 +29,8 @@ public class Order : AggregateRoot OrderItems = new List(); } - public void AddOrderItem(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, - int units = 1) + public void AddOrderItem(Guid productId, string productName, string productCode, decimal unitPrice, + decimal discount, string pictureUrl, int units = 1) { var existingOrderForProduct = OrderItems.SingleOrDefault(o => o.ProductId == productId); @@ -45,7 +45,7 @@ public class Order : AggregateRoot } else { - var orderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units); + var orderItem = new OrderItem(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 4c571174..8a56bcd9 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs @@ -7,6 +7,7 @@ namespace EShopOnAbp.OrderingService.Orders; public class OrderItem : Entity { + public string ProductCode { get; private set; } public string ProductName { get; private set; } public string PictureUrl { get; private set; } public decimal UnitPrice { get; private set; } @@ -16,7 +17,7 @@ public class OrderItem : Entity protected OrderItem() { } - public OrderItem(Guid productId, [NotNull]string productName, decimal unitPrice, decimal discount, [CanBeNull]string pictureUrl, int units = 1) + public OrderItem(Guid productId, [NotNull]string productName, [NotNull]string productCode, decimal unitPrice, decimal discount, [CanBeNull]string pictureUrl, int units = 1) { if (units <= 0) { @@ -30,6 +31,7 @@ public class OrderItem : Entity ProductId = productId; ProductName = Check.NotNullOrEmpty(productName, nameof(productName)); + ProductCode = Check.NotNullOrEmpty(productCode, nameof(productCode)); UnitPrice = unitPrice; Discount = discount; Units = units; diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs index 3cf3aed6..b16302f0 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs @@ -21,7 +21,8 @@ public class OrderManager : DomainService int paymentTypeId, string buyerName, string buyerEmail, - List<(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units)> + List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, string + pictureUrl, int units)> orderItems, string addressStreet, string addressCity, @@ -53,6 +54,7 @@ public class OrderManager : DomainService order.AddOrderItem( productId: orderItem.productId, productName: orderItem.productName, + productCode: orderItem.productCode, unitPrice: orderItem.unitPrice, discount: orderItem.discount, pictureUrl: orderItem.pictureUrl, diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs index db163a01..8c1ed97e 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs @@ -100,6 +100,7 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore b.Property("OrderId").IsRequired(); b.Property(q => q.ProductId).IsRequired(); + b.Property(q => q.ProductCode).IsRequired(); b.Property(q => q.ProductName).IsRequired(); b.Property(q => q.Discount).IsRequired(); b.Property(q => q.UnitPrice).IsRequired(); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231135901_Added-ProductCode.Designer.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231135901_Added-ProductCode.Designer.cs new file mode 100644 index 00000000..9b8fc6f5 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231135901_Added-ProductCode.Designer.cs @@ -0,0 +1,244 @@ +// +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("20211231135901_Added-ProductCode")] + partial class AddedProductCode + { + 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("PaymentMethodToken") + .HasColumnType("text"); + + 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/20211231135901_Added-ProductCode.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231135901_Added-ProductCode.cs new file mode 100644 index 00000000..e10a86ce --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211231135901_Added-ProductCode.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EShopOnAbp.OrderingService.Migrations +{ + public partial class AddedProductCode : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ProductCode", + table: "OrderItems", + type: "text", + nullable: false, + defaultValue: ""); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ProductCode", + table: "OrderItems"); + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs index 02fb559b..fa6c25fa 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -127,6 +127,10 @@ namespace EShopOnAbp.OrderingService.Migrations b.Property("PictureUrl") .HasColumnType("text"); + b.Property("ProductCode") + .IsRequired() + .HasColumnType("text"); + b.Property("ProductId") .HasColumnType("uuid"); From 7d6734dedbc4e9e92ffc0bb1268a025145ca57dd Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 31 Dec 2021 17:10:37 +0300 Subject: [PATCH 11/24] Updated payment --- .../EShopOnAbp.PublicWeb.csproj | 1 + .../EShopOnAbpPublicAutoMapperProfile.cs | 7 +++++ .../EShopOnAbpPublicWebModule.cs | 2 ++ .../Pages/Payment.cshtml.cs | 29 +++++++++++++++++++ .../DbMigrations/IdentityServerDataSeeder.cs | 5 ++-- .../Orders/OrderItemCreateDto.cs | 1 + .../Orders/OrderAppService.cs | 10 ++++--- 7 files changed, 49 insertions(+), 6 deletions(-) diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj index 7f718696..e96e613c 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbp.PublicWeb.csproj @@ -28,6 +28,7 @@ + diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs index 561a3ab2..b4bebecc 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs @@ -1,6 +1,8 @@ using AutoMapper; using EShopOnAbp.BasketService; +using EShopOnAbp.OrderingService.Orders; using EShopOnAbp.PaymentService.PaymentRequests; +using Volo.Abp.AutoMapper; namespace EShopOnAbp.PublicWeb { @@ -13,6 +15,11 @@ namespace EShopOnAbp.PublicWeb .ForMember(p => p.Name, opts => opts.MapFrom(p => p.ProductName)) .ForMember(p => p.UnitPrice, opts => opts.MapFrom(p => p.TotalPrice / p.Count)) .ForMember(p => p.Quantity, opts => opts.MapFrom(p => p.Count)); + + CreateMap() + .ForMember(p => p.Units, opts => opts.MapFrom(q => q.Count)) + .ForMember(p => p.PictureUrl, opts => opts.MapFrom(q => q.ImageName)) + .Ignore(q => q.Discount); } } } diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs index 146189d6..4d36f2a3 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs @@ -13,6 +13,7 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; using StackExchange.Redis; using System; using System.Net.Http.Headers; +using EShopOnAbp.OrderingService; using Volo.Abp; using Volo.Abp.Account; using Volo.Abp.AspNetCore.Authentication.OpenIdConnect; @@ -48,6 +49,7 @@ namespace EShopOnAbp.PublicWeb typeof(EShopOnAbpSharedLocalizationModule), typeof(CatalogServiceHttpApiClientModule), typeof(BasketServiceHttpApiClientModule), + typeof(OrderingServiceHttpApiClientModule), typeof(AbpAspNetCoreSignalRModule), typeof(PaymentServiceHttpApiClientModule), typeof(AbpAutoMapperModule) diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs index 2ecf2245..dca6651b 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs @@ -6,7 +6,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using EShopOnAbp.OrderingService.Orders; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.Users; @@ -16,16 +18,22 @@ namespace EShopOnAbp.PublicWeb.Pages; public class PaymentModel : AbpPageModel { private readonly IPaymentRequestAppService _paymentRequestAppService; + private readonly IOrderAppService _orderAppService; private readonly UserBasketProvider _userBasketProvider; + private readonly UserAddressProvider _userAddressProvider; private readonly EShopOnAbpPublicWebPaymentOptions _publicWebPaymentOptions; public PaymentModel( IPaymentRequestAppService paymentRequestAppService, + IOrderAppService orderAppService, UserBasketProvider userBasketProvider, + UserAddressProvider userAddressProvider, IOptions publicWebPaymentOptions) { _paymentRequestAppService = paymentRequestAppService; _userBasketProvider = userBasketProvider; + _userAddressProvider = userAddressProvider; + _orderAppService = orderAppService; _publicWebPaymentOptions = publicWebPaymentOptions.Value; } @@ -40,6 +48,14 @@ public class PaymentModel : AbpPageModel Logger.LogInformation($"PaymentId: {model.SelectedPaymentId}"); var basket = await _userBasketProvider.GetBasketAsync(); + var placedOrder = await _orderAppService.CreateAsync(new OrderCreateDto() + { + PaymentTypeId = 1, // Paypal + Address = GetUserAddress(model.SelectedAddressId), + Products = ObjectMapper.Map, List>(basket.Items) + }); + + var paymentRequest = await _paymentRequestAppService.CreateAsync(new PaymentRequestCreationDto { @@ -58,6 +74,19 @@ public class PaymentModel : AbpPageModel return Redirect(response.CheckoutLink); } + private OrderAddressDto GetUserAddress(int selectedAddressId) + { + var address = _userAddressProvider.GetDemoAddresses().First(q => q.Id == selectedAddressId); + return new OrderAddressDto + { + City = address.City, + Country = address.Country, + Description = address.Description, + Street = address.Street, + ZipCode = address.ZipCode + }; + } + public class PaymentPageViewModel { public int SelectedAddressId { get; set; } diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs index 3ddf3ba4..933110c5 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs @@ -217,9 +217,10 @@ namespace EShopOnAbp.IdentityService.DbMigrations scopes: commonScopes.Union(new[] { "AdministrationService", - "CatalogService", // Consider removing this service + "CatalogService", "BasketService", - "PaymentService" + "PaymentService", + "OrderingService" }), grantTypes: new[] { "hybrid" }, secret: "1q2w3e*".Sha256(), diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs index 5bb57765..ff554fcd 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderItemCreateDto.cs @@ -5,6 +5,7 @@ namespace EShopOnAbp.OrderingService.Orders; public class OrderItemCreateDto { public Guid ProductId { get; set; } + public string ProductCode { get; set; } public string ProductName { get; set; } public string PictureUrl { get; set; } public decimal UnitPrice { get; set; } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs index ceb76211..029c5c91 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -50,16 +50,18 @@ public class OrderAppService : ApplicationService, IOrderAppService return await CreateOrderDtoMappingAsync(placedOrder); } - private List<(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units + private List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, string + pictureUrl, int units )> GetProductListTuple(List products) { var orderItems = - new List<(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int + new List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, + string pictureUrl, int units)>(); foreach (var product in products) { - orderItems.Add((product.ProductId, product.ProductName, product.UnitPrice, product.Discount, - product.PictureUrl, product.Units)); + orderItems.Add((product.ProductId, product.ProductName, product.ProductCode, product.UnitPrice, + product.Discount, product.PictureUrl, product.Units)); } return orderItems; From 43b415b1a75958dddf6a123fd1612cc73a4eb23c Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 3 Jan 2022 22:13:05 +0300 Subject: [PATCH 12/24] Aded OrderPlacedEto and --- .../Buyers/BuyerEto.cs | 13 +++++ .../Orders/OrderItemEto.cs | 7 +-- .../Orders/OrderPlacedEto.cs | 16 ++++++ .../Orders/OrderManager.cs | 52 ++++++++++++++++++- 4 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs new file mode 100644 index 00000000..cc43c92c --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs @@ -0,0 +1,13 @@ +using System; +using Volo.Abp.Domain.Entities.Events.Distributed; + +namespace EShopOnAbp.OrderingService.Buyers; + +public class BuyerEto : EtoBase +{ + public Guid BuyerId { get; set; } + public string BuyerEmail { get; set; } + public string PaymentType { get; set; } + public int PaymentTypeId { get; set; } + +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderItemEto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderItemEto.cs index 049fda07..83bf27fc 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderItemEto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderItemEto.cs @@ -1,15 +1,16 @@ using System; +using Volo.Abp.Domain.Entities.Events.Distributed; namespace EShopOnAbp.OrderingService.Orders { - public class OrderItemEto + public class OrderItemEto : EtoBase { public Guid ProductId { get; set; } - + public string ProductCode { get; set; } public string ProductName { get; set; } public string PictureUrl { get; set; } public decimal UnitPrice { get; set; } public decimal Discount { get; set; } public int Units { get; set; } } -} +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs new file mode 100644 index 00000000..4ead8fbc --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using EShopOnAbp.OrderingService.Buyers; +using Volo.Abp.Domain.Entities.Events.Distributed; +using Volo.Abp.EventBus; + +namespace EShopOnAbp.OrderingService.Orders; + +[EventName("EShopOnAbp.Order.Placed")] +public class OrderPlacedEto : EtoBase +{ + public Guid OrderId { get; set; } + public BuyerEto Buyer { get; set; } + public DateTime OrderDate { get; set; } + public List Items { get; set; } = new(); +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs index b16302f0..d5de4077 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using EShopOnAbp.OrderingService.Buyers; using Volo.Abp.Domain.Services; +using Volo.Abp.EventBus.Distributed; namespace EShopOnAbp.OrderingService.Orders; @@ -10,11 +11,16 @@ public class OrderManager : DomainService { private readonly IOrderRepository _orderRepository; private readonly IBuyerRepository _buyerRepository; + private readonly IDistributedEventBus _distributedEventBus; - public OrderManager(IOrderRepository orderRepository, IBuyerRepository buyerRepository) + public OrderManager( + IOrderRepository orderRepository, + IBuyerRepository buyerRepository, + IDistributedEventBus distributedEventBus) { _orderRepository = orderRepository; _buyerRepository = buyerRepository; + _distributedEventBus = distributedEventBus; } public async Task CreateOrderAsync( @@ -62,6 +68,48 @@ public class OrderManager : DomainService ); } - return await _orderRepository.InsertAsync(order); + var placedOrder = await _orderRepository.InsertAsync(order, true); + + // Publish Order placed event + await _distributedEventBus.PublishAsync(new OrderPlacedEto + { + OrderId = placedOrder.Id, + OrderDate = placedOrder.OrderDate, + Buyer = GetBuyerEto(buyer), + Items = GetProductItemEtoList(order.OrderItems) + }); + + return placedOrder; + } + + private BuyerEto GetBuyerEto(Buyer buyer) + { + return new BuyerEto() + { + BuyerEmail = buyer.Email, + BuyerId = buyer.Id, + PaymentType = buyer.PaymentType.Name, + PaymentTypeId = buyer.PaymentType.Id + }; + } + + private List GetProductItemEtoList(List orderItems) + { + List etoList = new List(); + foreach (var oItem in orderItems) + { + etoList.Add(new OrderItemEto() + { + Discount = oItem.Discount, + PictureUrl = oItem.PictureUrl, + ProductCode = oItem.ProductCode, + ProductId = oItem.ProductId, + ProductName = oItem.ProductName, + UnitPrice = oItem.UnitPrice, + Units = oItem.Units + }); + } + + return etoList; } } \ No newline at end of file From 46809d2c073142231f835c0604ee8dc218612650 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 3 Jan 2022 22:13:37 +0300 Subject: [PATCH 13/24] updated basket service to handle orderplaced eto --- ...tedEventHandler.cs => OrderPlacedEventHandler.cs} | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) rename services/basket/src/EShopOnAbp.BasketService.Domain/Orders/{OrderAcceptedEventHandler.cs => OrderPlacedEventHandler.cs} (63%) diff --git a/services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderAcceptedEventHandler.cs b/services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderPlacedEventHandler.cs similarity index 63% rename from services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderAcceptedEventHandler.cs rename to services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderPlacedEventHandler.cs index 87324de1..7b9a9404 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderAcceptedEventHandler.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderPlacedEventHandler.cs @@ -5,22 +5,20 @@ using Volo.Abp.EventBus.Distributed; namespace EShopOnAbp.BasketService.Orders { - public class OrderAcceptedEventHandler : - IDistributedEventHandler, - ITransientDependency + public class OrderPlacedEventHandler : IDistributedEventHandler, ITransientDependency { private readonly IBasketRepository _basketRepository; - public OrderAcceptedEventHandler(IBasketRepository basketRepository) + public OrderPlacedEventHandler(IBasketRepository basketRepository) { _basketRepository = basketRepository; } - public async Task HandleEventAsync(OrderAcceptedEto eventData) + public async Task HandleEventAsync(OrderPlacedEto eventData) { - var basket = await _basketRepository.GetAsync(eventData.BuyerId); + var basket = await _basketRepository.GetAsync(eventData.Buyer.BuyerId); basket.Clear(); await _basketRepository.UpdateAsync(basket); } } -} +} \ No newline at end of file From 58af27ddae776a75fed338a52de616ef5aba7d1a Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Mon, 3 Jan 2022 22:14:44 +0300 Subject: [PATCH 14/24] OrderDto property renamed Products->Items --- .../Orders/OrderDto.cs | 2 +- .../OrderingServiceApplicationAutoMapperProfile.cs | 2 +- .../Orders/OrderAppService.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs index 7b0145e3..2ca2005c 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs @@ -12,5 +12,5 @@ public class OrderDto : EntityDto public string OrderStatus { get; set; } public BuyerDto Buyer { get; set; } public OrderAddressDto Address { get; set; } = new(); - public List Products { get; set; } = new(); + public List Items { get; set; } = new(); } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs index 3247f98a..1b970541 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs @@ -18,7 +18,7 @@ namespace EShopOnAbp.OrderingService CreateMap() .Ignore(q => q.Address) - .Ignore(q => q.Products) + .Ignore(q => q.Items) .Ignore(q => q.Buyer); } } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs index 029c5c91..f13da7fb 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -73,7 +73,7 @@ public class OrderAppService : ApplicationService, IOrderAppService return new OrderDto() { Address = ObjectMapper.Map(placedOrder.Address), - Products = ObjectMapper.Map, List>(placedOrder.OrderItems), + Items = ObjectMapper.Map, List>(placedOrder.OrderItems), Buyer = ObjectMapper.Map(buyer), Id = placedOrder.Id, OrderDate = placedOrder.OrderDate, From bb61c5a8552cda8ff3ef318ac77f807e6f5947bf Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 00:32:38 +0300 Subject: [PATCH 15/24] fixed payment service missing dto and renaming --- ...estProduct.cs => PaymentRequestProductDto.cs} | 2 +- .../PaymentRequests/PaymentRequestProduct.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) rename services/payment/src/EShopOnAbp.PaymentService.Application.Contracts/PaymentRequests/{PaymentRequestProduct.cs => PaymentRequestProductDto.cs} (88%) diff --git a/services/payment/src/EShopOnAbp.PaymentService.Application.Contracts/PaymentRequests/PaymentRequestProduct.cs b/services/payment/src/EShopOnAbp.PaymentService.Application.Contracts/PaymentRequests/PaymentRequestProductDto.cs similarity index 88% rename from services/payment/src/EShopOnAbp.PaymentService.Application.Contracts/PaymentRequests/PaymentRequestProduct.cs rename to services/payment/src/EShopOnAbp.PaymentService.Application.Contracts/PaymentRequests/PaymentRequestProductDto.cs index 7974d693..4246e772 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.Application.Contracts/PaymentRequests/PaymentRequestProduct.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.Application.Contracts/PaymentRequests/PaymentRequestProductDto.cs @@ -5,7 +5,7 @@ namespace EShopOnAbp.PaymentService.PaymentRequests { public class PaymentRequestProductDto : EntityDto { - public Guid PaymentRequestId { get; private set; } + public Guid PaymentRequestId { get; set; } public string ReferenceId { get; set; } diff --git a/services/payment/src/EShopOnAbp.PaymentService.Domain/PaymentRequests/PaymentRequestProduct.cs b/services/payment/src/EShopOnAbp.PaymentService.Domain/PaymentRequests/PaymentRequestProduct.cs index 353387b9..7d3b8055 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.Domain/PaymentRequests/PaymentRequestProduct.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.Domain/PaymentRequests/PaymentRequestProduct.cs @@ -8,12 +8,12 @@ namespace EShopOnAbp.PaymentService.PaymentRequests public class PaymentRequestProduct : Entity { public Guid PaymentRequestId { get; private set; } - public string ReferenceId { get; set; } - public string Code { get; set; } - public string Name { get; set; } - public decimal UnitPrice { get; set; } - public int Quantity { get; set; } - public decimal TotalPrice { get; set; } + public string ReferenceId { get; private set; } + public string Code { get; private set; } + public string Name { get; private set; } + public decimal UnitPrice { get; private set; } + public int Quantity { get; private set; } + public decimal TotalPrice { get; private set; } public PaymentRequestProduct( Guid id, @@ -26,8 +26,8 @@ namespace EShopOnAbp.PaymentService.PaymentRequests [CanBeNull] string referenceId = null) : base(id) { PaymentRequestId = paymentRequestId; - Code = Check.NotNullOrEmpty(code, nameof(code)); - Name = Check.NotNullOrEmpty(name, nameof(name)); + Code = Check.NotNullOrEmpty(code, nameof(code), maxLength: PaymentRequestConsts.MaxCodeLength); + Name = Check.NotNullOrEmpty(name, nameof(name), maxLength: PaymentRequestConsts.MaxNameLength); UnitPrice = unitPrice; Quantity = quantity; TotalPrice = totalPrice; From e1423bef46876274b02e5f86f047a5ae62908f61 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 02:03:08 +0300 Subject: [PATCH 16/24] updated order manager with order completion progress still missing payment token update --- .../Localization/OrderingService/en.json | 3 ++- .../Localization/OrderingService/tr.json | 3 ++- .../OrderingServiceErrorCodes.cs | 21 +++++++++---------- .../Orders/Order.cs | 12 ++++++++++- .../Orders/OrderManager.cs | 18 +++++++++++++++- .../PaymentRequestEventHandler.cs | 5 ++--- 6 files changed, 44 insertions(+), 18 deletions(-) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json index 84aad32a..c37a8dab 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json @@ -7,6 +7,7 @@ "Ordering:00011": "Possible values for Payment types: {0}", "Ordering:00002": "Invalid number of units", "Ordering:00003": "Invalid discount", - "Ordering:00004": "The total of order item is lower than applied discount" + "Ordering:00004": "The total of order item is lower than applied discount", + "Ordering:01001": "Order with {0} id could not be found!" } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json index 14f3eea7..8c6099ad 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json @@ -7,6 +7,7 @@ "Ordering:00011": "Muhtemel Ödeme türleri: {0}", "Ordering:00002": "Ürün adedi negatif olamaz", "Ordering:00003": "Geçersiz indirim", - "Ordering:00004": "Ürünlerin toplam bedeli, uygulanan indirimden daha az olamaz" + "Ordering:00004": "Ürünlerin toplam bedeli, uygulanan indirimden daha az olamaz", + "Ordering:01001": "{0} ID numaralı ürün bulunamadı!" } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs index f4ab7c19..08f9a0e0 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs @@ -1,12 +1,11 @@ -namespace EShopOnAbp.OrderingService +namespace EShopOnAbp.OrderingService; + +public static class OrderingServiceErrorCodes { - public static class OrderingServiceErrorCodes - { - public const string OrderingStatusNotFound = "Ordering:00001"; - public const string PaymentTypeNotFound = "Ordering:00011"; - public const string InvalidUnits = "Ordering:00002"; - public const string InvalidDiscount = "Ordering:00003"; - public const string InvalidTotalForDiscount = "Ordering:00004"; - - } -} + public const string OrderingStatusNotFound = "Ordering:00001"; + public const string PaymentTypeNotFound = "Ordering:00011"; + public const string InvalidUnits = "Ordering:00002"; + public const string InvalidDiscount = "Ordering:00003"; + public const string InvalidTotalForDiscount = "Ordering:00004"; + public const string OrderWithIdNotFound = "Ordering:01001"; +} \ 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 6086847d..50e91850 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -22,6 +22,7 @@ public class Order : AggregateRoot internal Order(Guid id, Address address, Guid? buyerId = null, string paymentMethodToken = null) : base(id) { _orderStatusId = OrderStatus.Placed.Id; + OrderStatus = OrderStatus.Placed; OrderDate = DateTime.UtcNow; Address = address; BuyerId = buyerId; @@ -29,7 +30,14 @@ public class Order : AggregateRoot OrderItems = new List(); } - public void AddOrderItem(Guid productId, string productName, string productCode, decimal unitPrice, + internal Order SetOrderPaid() + { + OrderStatus = OrderStatus.Paid; + + return this; + } + + public Order AddOrderItem(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, string pictureUrl, int units = 1) { var existingOrderForProduct = OrderItems.SingleOrDefault(o => o.ProductId == productId); @@ -48,6 +56,8 @@ public class Order : AggregateRoot var orderItem = new OrderItem(productId, productName, productCode, unitPrice, discount, pictureUrl, units); OrderItems.Add(orderItem); } + + return this; } public decimal GetTotal() diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs index d5de4077..2007aca7 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using EShopOnAbp.OrderingService.Buyers; +using Volo.Abp; using Volo.Abp.Domain.Services; using Volo.Abp.EventBus.Distributed; @@ -69,7 +70,7 @@ public class OrderManager : DomainService } var placedOrder = await _orderRepository.InsertAsync(order, true); - + // Publish Order placed event await _distributedEventBus.PublishAsync(new OrderPlacedEto { @@ -82,6 +83,21 @@ public class OrderManager : DomainService return placedOrder; } + public async Task AcceptOrderAsync(Guid orderId) + { + var order = await _orderRepository.GetAsync(orderId); + if (order == null) + { + throw new BusinessException(OrderingServiceErrorCodes.OrderWithIdNotFound) + .WithData("OrderId", orderId); + } + + //Update order.PaymentMethodToken + order.SetOrderPaid(); + + return await _orderRepository.UpdateAsync(order); + } + private BuyerEto GetBuyerEto(Buyer buyer) { return new BuyerEto() diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs index 13c934b0..585eb993 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs @@ -9,8 +9,7 @@ using Volo.Abp.EventBus.Distributed; namespace EShopOnAbp.OrderingService.PaymentRequests { - public class PaymentRequestEventHandler : - IDistributedEventHandler, + public class PaymentRequestEventHandler : IDistributedEventHandler, ITransientDependency { private readonly IDistributedEventBus _eventBus; @@ -42,4 +41,4 @@ namespace EShopOnAbp.OrderingService.PaymentRequests }; } } -} +} \ No newline at end of file From 4cb18afe4a8edd3d8575391cad103879459ab6d0 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 02:05:40 +0300 Subject: [PATCH 17/24] fixed public web mapper config --- .../EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs index b4bebecc..6d5f87e8 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicAutoMapperProfile.cs @@ -12,11 +12,13 @@ namespace EShopOnAbp.PublicWeb { CreateMap() .ForMember(p => p.ReferenceId, opts => opts.MapFrom(p => p.ProductId.ToString())) + .ForMember(p => p.Code, opts => opts.MapFrom(p => p.ProductCode)) .ForMember(p => p.Name, opts => opts.MapFrom(p => p.ProductName)) .ForMember(p => p.UnitPrice, opts => opts.MapFrom(p => p.TotalPrice / p.Count)) .ForMember(p => p.Quantity, opts => opts.MapFrom(p => p.Count)); CreateMap() + .ForMember(p => p.UnitPrice, opts => opts.MapFrom(q => q.TotalPrice)) .ForMember(p => p.Units, opts => opts.MapFrom(q => q.Count)) .ForMember(p => p.PictureUrl, opts => opts.MapFrom(q => q.ImageName)) .Ignore(q => q.Discount); From 718f3aa70ea4720b8877d6da450524f92c836e2f Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 02:08:06 +0300 Subject: [PATCH 18/24] added ordering service scope --- .../src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs index 4d36f2a3..d078009f 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs @@ -127,6 +127,7 @@ namespace EShopOnAbp.PublicWeb options.Scope.Add("BasketService"); options.Scope.Add("CatalogService"); options.Scope.Add("PaymentService"); + options.Scope.Add("OrderingService"); }); var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); From 56c50d279868b111878737978539f4dffba7bb07 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 12:35:12 +0300 Subject: [PATCH 19/24] fixed static proxy --- .../OrderingService-generate-proxy.json | 53 ------------------- .../SampleClientProxy.Generated.cs | 15 ------ .../ClientProxies/SampleClientProxy.cs | 8 --- .../OrderingServiceHttpApiClientModule.cs | 5 +- .../OrderingServiceHttpApiHostModule.cs | 4 +- 5 files changed, 5 insertions(+), 80 deletions(-) delete mode 100644 services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderingService-generate-proxy.json delete mode 100644 services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/SampleClientProxy.Generated.cs delete mode 100644 services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/SampleClientProxy.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderingService-generate-proxy.json b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderingService-generate-proxy.json deleted file mode 100644 index cb296e04..00000000 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/OrderingService-generate-proxy.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "modules": { - "OrderingService": { - "rootPath": "OrderingService", - "remoteServiceName": "OrderingService", - "controllers": { - "EShopOnAbp.OrderingService.Samples.SampleController": { - "controllerName": "Sample", - "controllerGroupName": "Sample", - "type": "EShopOnAbp.OrderingService.Samples.SampleController", - "interfaces": [ - { - "type": "EShopOnAbp.OrderingService.Samples.ISampleAppService" - } - ], - "actions": { - "GetAsync": { - "uniqueName": "GetAsync", - "name": "GetAsync", - "httpMethod": "GET", - "url": "api/OrderingService/sample", - "supportedVersions": [], - "parametersOnMethod": [], - "parameters": [], - "returnValue": { - "type": "EShopOnAbp.OrderingService.Samples.SampleDto", - "typeSimple": "EShopOnAbp.OrderingService.Samples.SampleDto" - }, - "allowAnonymous": null, - "implementFrom": "EShopOnAbp.OrderingService.Samples.ISampleAppService" - }, - "GetAuthorizedAsync": { - "uniqueName": "GetAuthorizedAsync", - "name": "GetAuthorizedAsync", - "httpMethod": "GET", - "url": "api/OrderingService/sample/authorized", - "supportedVersions": [], - "parametersOnMethod": [], - "parameters": [], - "returnValue": { - "type": "EShopOnAbp.OrderingService.Samples.SampleDto", - "typeSimple": "EShopOnAbp.OrderingService.Samples.SampleDto" - }, - "allowAnonymous": false, - "implementFrom": "EShopOnAbp.OrderingService.Samples.ISampleAppService" - } - } - } - } - } - }, - "types": {} -} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/SampleClientProxy.Generated.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/SampleClientProxy.Generated.cs deleted file mode 100644 index dd18ffb4..00000000 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/SampleClientProxy.Generated.cs +++ /dev/null @@ -1,15 +0,0 @@ -// This file is automatically generated by ABP framework to use MVC Controllers from CSharp -using System; -using System.Threading.Tasks; -using Volo.Abp.Application.Dtos; -using Volo.Abp.Http.Client; -using Volo.Abp.Http.Modeling; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Http.Client.ClientProxying; -using EShopOnAbp.OrderingService.Samples; - -// ReSharper disable once CheckNamespace -namespace EShopOnAbp.OrderingService.Samples.ClientProxies -{ - -} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/SampleClientProxy.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/SampleClientProxy.cs deleted file mode 100644 index 9cd1a763..00000000 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/ClientProxies/SampleClientProxy.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This file is part of SampleClientProxy, you can customize it here -// ReSharper disable once CheckNamespace -namespace EShopOnAbp.OrderingService.Samples.ClientProxies -{ - public partial class SampleClientProxy - { - } -} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/OrderingServiceHttpApiClientModule.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/OrderingServiceHttpApiClientModule.cs index e52daa5c..762bb7f6 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/OrderingServiceHttpApiClientModule.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Client/OrderingServiceHttpApiClientModule.cs @@ -10,11 +10,12 @@ namespace EShopOnAbp.OrderingService typeof(AbpHttpClientModule))] public class OrderingServiceHttpApiClientModule : AbpModule { + public const string RemoteServiceName = "Ordering"; public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddHttpClientProxies( + context.Services.AddStaticHttpClientProxies( typeof(OrderingServiceApplicationContractsModule).Assembly, - OrderingServiceRemoteServiceConsts.RemoteServiceName + RemoteServiceName ); Configure(options => diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs index 41d0ba31..3d0f5eea 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs @@ -66,8 +66,8 @@ namespace EShopOnAbp.OrderingService { options.ConventionalControllers.Create(typeof(OrderingServiceApplicationModule).Assembly, opts => { - opts.RootPath = OrderingServiceRemoteServiceConsts.RemoteServiceName.ToLowerInvariant(); - opts.RemoteServiceName = OrderingServiceRemoteServiceConsts.RemoteServiceName; + opts.RootPath = "ordering"; + opts.RemoteServiceName = "Ordering"; }); }); } From 2479b2588ff7cacfd8f6d5c0274bf1e518a27262 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 12:39:12 +0300 Subject: [PATCH 20/24] 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") From 1314353806d716e9334a697e363cd6e47006ac89 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 12:39:51 +0300 Subject: [PATCH 21/24] Updated payment types Only paypal and demo --- .../src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs | 2 +- .../EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs index 6ab142e4..451eccfd 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs @@ -21,7 +21,7 @@ public class Buyer : AggregateRoot [NotNull] string email, PaymentType paymentType) : base(id) { - _paymentTypeId = PaymentType.FromName(paymentType.Name).Id; + _paymentTypeId = paymentType.Id; Name = Check.NotNullOrEmpty(name, nameof(name)); Email = Check.NotNullOrEmpty(email, nameof(email)); } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs index afd15501..5ee66b7b 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs @@ -8,15 +8,14 @@ namespace EShopOnAbp.OrderingService.Buyers; public class PaymentType : Enumeration { public static PaymentType Paypal = new PaymentType(1, nameof(Paypal).ToLowerInvariant()); - public static PaymentType Visa = new PaymentType(1, nameof(Visa).ToLowerInvariant()); - public static PaymentType MasterCard = new PaymentType(1, nameof(MasterCard).ToLowerInvariant()); + public static PaymentType Demo = new PaymentType(2, nameof(Paypal).ToLowerInvariant()); public PaymentType(int id, string name) : base(id, name) { } public static IEnumerable List() => - new[] {Paypal, Visa, Visa, MasterCard}; + new[] {Paypal, Demo}; public static PaymentType FromName(string name) { From fde19634df17ba23a6b5a5fdfc9005df878074ea Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 12:41:23 +0300 Subject: [PATCH 22/24] Added OrderManager unit test and repository updates with eager loading --- .../Buyers/EfCoreBuyerRepository.cs | 18 +++++++++ .../Orders/EfCoreOrderRepository.cs | 21 ++++++++++- .../Orders/OrderManager_Tests.cs | 37 +++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs index 8e0760d1..aa56abcb 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs @@ -1,5 +1,9 @@ using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using EShopOnAbp.OrderingService.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -11,4 +15,18 @@ public class EfCoreBuyerRepository : EfCoreRepository InsertAsync(Buyer entity, bool autoSave = false, + CancellationToken cancellationToken = new CancellationToken()) + { + var newEntity = await base.InsertAsync(entity, autoSave, cancellationToken); + await EnsurePropertyLoadedAsync(newEntity, query => query.PaymentType, cancellationToken); + return newEntity; + } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()) + .Include(q => q.PaymentType); + } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs index a1b3ec37..d63ef3cd 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs @@ -1,5 +1,9 @@ using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using EShopOnAbp.OrderingService.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -7,7 +11,22 @@ namespace EShopOnAbp.OrderingService.Orders; public class EfCoreOrderRepository : EfCoreRepository, IOrderRepository { - public EfCoreOrderRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) + public EfCoreOrderRepository(IDbContextProvider dbContextProvider) : base( + dbContextProvider) { } + + public override async Task InsertAsync(Order entity, bool autoSave = false, + CancellationToken cancellationToken = new CancellationToken()) + { + var newEntity = await base.InsertAsync(entity, autoSave, cancellationToken); + await EnsurePropertyLoadedAsync(newEntity, o => o.OrderStatus, cancellationToken); + return newEntity; + } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()) + .Include(q => q.OrderStatus); + } } \ No newline at end of file diff --git a/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs b/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs new file mode 100644 index 00000000..0b55ed8f --- /dev/null +++ b/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Shouldly; +using Xunit; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderManagerUnitTests : OrderingServiceDomainTestBase +{ + private readonly OrderManager _orderManager; + + public OrderManagerUnitTests() + { + _orderManager = GetRequiredService(); + } + + [Fact] + public async Task Should_CreateOrderAsync() + { + var orderItems = + new List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, + string pictureUrl, int + units)>(); + orderItems.Add((Guid.NewGuid(), "Test product", "Code:001", 15, 0, "", 1)); + var createdOrder = await _orderManager.CreateOrderAsync( + 1, + "gterdem", + "gterdem@volosoft.com", + orderItems, + "Test Street", + "Test City", + "Test Country", + "Test zipCode"); + createdOrder.ShouldNotBeNull(); + } +} \ No newline at end of file From 42d68a98304b52fa1cef7498e133a23644e4b335 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 15:48:29 +0300 Subject: [PATCH 23/24] fixed unit test compile error --- .../Orders/OrderManager_Tests.cs | 5 +++++ .../ClientDemoService.cs | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs b/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs index 0b55ed8f..78708aae 100644 --- a/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs +++ b/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using EShopOnAbp.OrderingService.Buyers; using Shouldly; using Xunit; @@ -25,6 +26,7 @@ public class OrderManagerUnitTests : OrderingServiceDomainTestBase orderItems.Add((Guid.NewGuid(), "Test product", "Code:001", 15, 0, "", 1)); var createdOrder = await _orderManager.CreateOrderAsync( 1, + Guid.Parse("11CA0F6D-208E-441A-9F9B-3611C96E4383"), "gterdem", "gterdem@volosoft.com", orderItems, @@ -32,6 +34,9 @@ public class OrderManagerUnitTests : OrderingServiceDomainTestBase "Test City", "Test Country", "Test zipCode"); + createdOrder.ShouldNotBeNull(); + createdOrder.OrderStatus.ShouldBe(OrderStatus.Placed); + createdOrder.PaymentType.ShouldBe(PaymentType.Paypal); } } \ No newline at end of file diff --git a/services/ordering/test/EShopOnAbp.OrderingService.HttpApi.Client.ConsoleTestApp/ClientDemoService.cs b/services/ordering/test/EShopOnAbp.OrderingService.HttpApi.Client.ConsoleTestApp/ClientDemoService.cs index e57415d3..0b012539 100644 --- a/services/ordering/test/EShopOnAbp.OrderingService.HttpApi.Client.ConsoleTestApp/ClientDemoService.cs +++ b/services/ordering/test/EShopOnAbp.OrderingService.HttpApi.Client.ConsoleTestApp/ClientDemoService.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Threading.Tasks; using IdentityModel.Client; using Microsoft.Extensions.Configuration; -using EShopOnAbp.OrderingService.Samples; using Volo.Abp.DependencyInjection; using Volo.Abp.IdentityModel; From 88380f5d911b902aeb611982134f949175479e34 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 4 Jan 2022 15:49:36 +0300 Subject: [PATCH 24/24] Removed Buyer Domain -> Added Buyer Value Object --- .../Pages/Payment.cshtml.cs | 3 +- .../Orders/OrderPlacedEventHandler.cs | 4 +- .../{Buyers => Orders}/BuyerDto.cs | 4 +- .../Orders/OrderDto.cs | 3 +- ...ringServiceApplicationAutoMapperProfile.cs | 6 +- .../Orders/OrderAppService.cs | 15 +- .../Buyers/BuyerEto.cs | 13 - .../OrderingServiceErrorCodes.cs | 1 + .../Orders/BuyerEto.cs | 11 + .../Orders/OrderAcceptedEto.cs | 3 +- .../Orders/OrderPlacedEto.cs | 3 +- .../Buyers/Buyer.cs | 28 --- .../Buyers/IBuyerRepository.cs | 8 - .../Orders/Buyer.cs | 31 +++ .../Orders/Order.cs | 22 +- .../Orders/OrderManager.cs | 40 +-- .../{Buyers => Orders}/PaymentType.cs | 0 .../PaymentRequestEventHandler.cs | 26 +- .../Buyers/EfCoreBuyerRepository.cs | 32 --- .../IOrderingServiceDbContext.cs | 4 +- .../OrderingServiceDbContext.cs | 89 ++++--- ...104115822_Removed_Buyer_Domain.Designer.cs | 230 ++++++++++++++++++ .../20220104115822_Removed_Buyer_Domain.cs | 137 +++++++++++ .../OrderingServiceDbContextModelSnapshot.cs | 92 +++---- .../Orders/EfCoreOrderRepository.cs | 10 +- 25 files changed, 563 insertions(+), 252 deletions(-) rename services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/{Buyers => Orders}/BuyerDto.cs (55%) delete mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/BuyerEto.cs delete mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs delete mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/IBuyerRepository.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Buyer.cs rename services/ordering/src/EShopOnAbp.OrderingService.Domain/{Buyers => Orders}/PaymentType.cs (100%) delete mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104115822_Removed_Buyer_Domain.Designer.cs create mode 100644 services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104115822_Removed_Buyer_Domain.cs diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs index dca6651b..797aac15 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Payment.cshtml.cs @@ -54,11 +54,10 @@ public class PaymentModel : AbpPageModel Address = GetUserAddress(model.SelectedAddressId), Products = ObjectMapper.Map, List>(basket.Items) }); - - var paymentRequest = await _paymentRequestAppService.CreateAsync(new PaymentRequestCreationDto { + OrderId = placedOrder.Id.ToString(), BuyerId = CurrentUser.GetId().ToString(), Currency = EShopOnAbpPaymentConsts.Currency, Products = ObjectMapper.Map, List>(basket.Items) diff --git a/services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderPlacedEventHandler.cs b/services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderPlacedEventHandler.cs index 7b9a9404..d5b32341 100644 --- a/services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderPlacedEventHandler.cs +++ b/services/basket/src/EShopOnAbp.BasketService.Domain/Orders/OrderPlacedEventHandler.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.EventBus.Distributed; +using Volo.Abp.Uow; namespace EShopOnAbp.BasketService.Orders { @@ -14,9 +15,10 @@ namespace EShopOnAbp.BasketService.Orders _basketRepository = basketRepository; } + [UnitOfWork] public async Task HandleEventAsync(OrderPlacedEto eventData) { - var basket = await _basketRepository.GetAsync(eventData.Buyer.BuyerId); + var basket = await _basketRepository.GetAsync(eventData.Buyer.BuyerId.GetValueOrDefault()); basket.Clear(); await _basketRepository.UpdateAsync(basket); } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Buyers/BuyerDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/BuyerDto.cs similarity index 55% rename from services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Buyers/BuyerDto.cs rename to services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/BuyerDto.cs index e8e8b56d..24664a52 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Buyers/BuyerDto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/BuyerDto.cs @@ -1,12 +1,10 @@ using System; using Volo.Abp.Application.Dtos; -namespace EShopOnAbp.OrderingService.Buyers; +namespace EShopOnAbp.OrderingService.Orders; public class BuyerDto : EntityDto { public string Name { get; set; } public string Email { get; set; } - public string PaymentType { get; set; } - public int PaymentTypeId { get; set; } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs index 2ca2005c..eb6368ef 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/OrderDto.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using EShopOnAbp.OrderingService.Buyers; using Volo.Abp.Application.Dtos; namespace EShopOnAbp.OrderingService.Orders; @@ -10,6 +9,8 @@ public class OrderDto : EntityDto public DateTime OrderDate { get; set; } public int OrderStatusId { get; set; } public string OrderStatus { get; set; } + public int PaymentTypeId { get; set; } + public string PaymentType { get; set; } public BuyerDto Buyer { get; set; } public OrderAddressDto Address { get; set; } = new(); public List Items { get; set; } = new(); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs index 1b970541..f5f73fab 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/OrderingServiceApplicationAutoMapperProfile.cs @@ -10,12 +10,10 @@ namespace EShopOnAbp.OrderingService public OrderingServiceApplicationAutoMapperProfile() { CreateMap(); + CreateMap(); CreateMap(); - CreateMap() - .ForMember(q => q.PaymentType, opt => opt.MapFrom(q => q.PaymentType.Name)) - .ForMember(q => q.PaymentTypeId, opt => opt.MapFrom(q => q.PaymentType.Id)); - + CreateMap() .Ignore(q => q.Address) .Ignore(q => q.Items) diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs index f13da7fb..bdb3fd17 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using EShopOnAbp.OrderingService.Buyers; using EShopOnAbp.OrderingService.Localization; using Volo.Abp.Application.Services; +using Volo.Abp.Users; namespace EShopOnAbp.OrderingService.Orders; @@ -11,15 +12,13 @@ public class OrderAppService : ApplicationService, IOrderAppService { private readonly OrderManager _orderManager; private readonly IOrderRepository _orderRepository; - private readonly IBuyerRepository _buyerRepository; public OrderAppService(OrderManager orderManager, - IOrderRepository orderRepository, - IBuyerRepository buyerRepository) + IOrderRepository orderRepository + ) { _orderManager = orderManager; _orderRepository = orderRepository; - _buyerRepository = buyerRepository; LocalizationResource = typeof(OrderingServiceResource); ObjectMapperContext = typeof(OrderingServiceApplicationModule); } @@ -37,6 +36,7 @@ public class OrderAppService : ApplicationService, IOrderAppService var placedOrder = await _orderManager.CreateOrderAsync ( paymentTypeId: input.PaymentTypeId, + buyerId: CurrentUser.GetId(), buyerName: CurrentUser.Name, buyerEmail: CurrentUser.Email, orderItems: orderItems, @@ -69,16 +69,17 @@ public class OrderAppService : ApplicationService, IOrderAppService private async Task CreateOrderDtoMappingAsync(Order placedOrder) { - var buyer = await _buyerRepository.GetAsync(placedOrder.BuyerId.GetValueOrDefault()); return new OrderDto() { Address = ObjectMapper.Map(placedOrder.Address), Items = ObjectMapper.Map, List>(placedOrder.OrderItems), - Buyer = ObjectMapper.Map(buyer), + Buyer = ObjectMapper.Map(placedOrder.Buyer), Id = placedOrder.Id, OrderDate = placedOrder.OrderDate, OrderStatus = placedOrder.OrderStatus.Name, - OrderStatusId = placedOrder.OrderStatus.Id + OrderStatusId = placedOrder.OrderStatus.Id, + PaymentType = placedOrder.PaymentType.Name, + PaymentTypeId = placedOrder.PaymentType.Id }; } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs deleted file mode 100644 index cc43c92c..00000000 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using Volo.Abp.Domain.Entities.Events.Distributed; - -namespace EShopOnAbp.OrderingService.Buyers; - -public class BuyerEto : EtoBase -{ - public Guid BuyerId { get; set; } - public string BuyerEmail { get; set; } - public string PaymentType { get; set; } - public int PaymentTypeId { get; set; } - -} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs index 08f9a0e0..00310165 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs @@ -7,5 +7,6 @@ public static class OrderingServiceErrorCodes public const string InvalidUnits = "Ordering:00002"; public const string InvalidDiscount = "Ordering:00003"; public const string InvalidTotalForDiscount = "Ordering:00004"; + public const string OrderIdIdNotGuid = "Ordering:01000"; public const string OrderWithIdNotFound = "Ordering:01001"; } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/BuyerEto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/BuyerEto.cs new file mode 100644 index 00000000..0c8fba17 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/BuyerEto.cs @@ -0,0 +1,11 @@ +using System; +using Volo.Abp.Domain.Entities.Events.Distributed; + +namespace EShopOnAbp.OrderingService.Orders; + +public class BuyerEto : EtoBase +{ + public Guid? BuyerId { get; set; } + public string BuyerEmail { get; set; } + public string BuyerName { get; set; } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderAcceptedEto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderAcceptedEto.cs index 811f829a..f88d2f57 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderAcceptedEto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderAcceptedEto.cs @@ -10,7 +10,8 @@ namespace EShopOnAbp.OrderingService.Orders public class OrderAcceptedEto : EtoBase { public Guid OrderId { get; set; } - public Guid BuyerId { get; set; } + public string PaymentStatus { get; set; } + public BuyerEto Buyer { get; set; } public List Items { get; set; } } } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs index 4ead8fbc..5fea3949 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using EShopOnAbp.OrderingService.Buyers; using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.EventBus; @@ -10,7 +9,7 @@ namespace EShopOnAbp.OrderingService.Orders; public class OrderPlacedEto : EtoBase { public Guid OrderId { get; set; } - public BuyerEto Buyer { get; set; } public DateTime OrderDate { get; set; } + public BuyerEto Buyer { get; set; } public List Items { get; set; } = new(); } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs deleted file mode 100644 index 451eccfd..00000000 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using JetBrains.Annotations; -using Volo.Abp; -using Volo.Abp.Domain.Entities; - -namespace EShopOnAbp.OrderingService.Buyers; - -public class Buyer : AggregateRoot -{ - private int _paymentTypeId; - public string Name { get; private set; } - public string Email { get; private set; } - public PaymentType PaymentType { get; private set; } - - private Buyer() - { - } - - internal Buyer(Guid id, - [NotNull] string name, - [NotNull] string email, - PaymentType paymentType) : base(id) - { - _paymentTypeId = paymentType.Id; - Name = Check.NotNullOrEmpty(name, nameof(name)); - Email = Check.NotNullOrEmpty(email, nameof(email)); - } -} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/IBuyerRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/IBuyerRepository.cs deleted file mode 100644 index 1746b2f7..00000000 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/IBuyerRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; -using Volo.Abp.Domain.Repositories; - -namespace EShopOnAbp.OrderingService.Buyers; - -public interface IBuyerRepository : IRepository -{ -} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Buyer.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Buyer.cs new file mode 100644 index 00000000..b02d3e7b --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Buyer.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using Volo.Abp; +using Volo.Abp.Domain.Values; + +namespace EShopOnAbp.OrderingService.Orders; + +public class Buyer: ValueObject +{ + public Guid? Id { get; private set; } + public string Name { get; private set; } + public string Email { get; private set; } + + private Buyer() + { + + } + + public Buyer(string email, string name, Guid? id) + { + Name = Check.NotNullOrEmpty(name, nameof(name)); + Email = Check.NotNullOrEmpty(email, nameof(email)); + Id = id; + } + protected override IEnumerable GetAtomicValues() + { + yield return Id; + yield return Name; + yield return Email; + } +} \ 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 426ab6a3..28e56344 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using EShopOnAbp.OrderingService.Buyers; using Volo.Abp.Domain.Entities; namespace EShopOnAbp.OrderingService.Orders; @@ -8,10 +9,13 @@ namespace EShopOnAbp.OrderingService.Orders; public class Order : AggregateRoot { private int _orderStatusId; + private int _paymentTypeId; public DateTime OrderDate { get; private set; } - public Guid? BuyerId { get; private set; } - public Guid? PaymentRequestId { get; private set; } - public string PaymentStatus { get; private set; } + + public PaymentType PaymentType { get; private set; } + public Guid? PaymentRequestId { get; private set; } + public string PaymentStatus { get; private set; } + public Buyer Buyer { get; private set; } public Address Address { get; private set; } public OrderStatus OrderStatus { get; private set; } public List OrderItems { get; private set; } @@ -20,19 +24,22 @@ public class Order : AggregateRoot { } - internal Order(Guid id, Address address, Guid? buyerId = null, Guid? paymentRequestId = null) : base(id) + internal Order(Guid id, Buyer buyer, Address address,PaymentType paymentType, Guid? paymentRequestId = null) : base(id) { _orderStatusId = OrderStatus.Placed.Id; + _paymentTypeId = paymentType.Id; OrderDate = DateTime.UtcNow; + Buyer = buyer; Address = address; - BuyerId = buyerId; PaymentRequestId = paymentRequestId; PaymentStatus = "Waiting"; // TODO: magic string OrderItems = new List(); } - internal Order SetOrderPaid() + internal Order SetOrderAccepted(Guid paymentRequestId, string paymentRequestStatus) { + PaymentRequestId = paymentRequestId; + PaymentStatus = paymentRequestStatus; OrderStatus = OrderStatus.Paid; return this; @@ -54,7 +61,8 @@ public class Order : AggregateRoot } else { - var orderItem = new OrderItem(id, 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/OrderManager.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs index abec3d92..fac49843 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs @@ -3,33 +3,27 @@ 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; 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, UnitOfWorkManager unitOfWorkManager) + IDistributedEventBus distributedEventBus) { _orderRepository = orderRepository; - _buyerRepository = buyerRepository; _distributedEventBus = distributedEventBus; - _unitOfWorkManager = unitOfWorkManager; } public async Task CreateOrderAsync( int paymentTypeId, + Guid buyerId, string buyerName, string buyerEmail, List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, string @@ -42,23 +36,16 @@ public class OrderManager : DomainService string addressDescription = null ) { - // Create buyer - Buyer buyer = await _buyerRepository.InsertAsync( - new Buyer(GuidGenerator.Create(), buyerName, buyerEmail, PaymentType.From(paymentTypeId)), - autoSave: true - ); - - var insertedBuyer = await _buyerRepository.GetAsync(buyer.Id, includeDetails: true); - // Create new order Order order = new Order( id: GuidGenerator.Create(), + buyer: new Buyer(buyerEmail, buyerName, buyerId), address: new Address(street: addressStreet, city: addressCity, country: addressCountry, zipcode: addressZipCode, description: addressDescription), - buyerId: buyer.Id + paymentType: PaymentType.From(paymentTypeId) ); // Add new order items @@ -78,19 +65,20 @@ public class OrderManager : DomainService var placedOrder = await _orderRepository.InsertAsync(order, true); + // Publish Order placed event await _distributedEventBus.PublishAsync(new OrderPlacedEto { OrderId = placedOrder.Id, OrderDate = placedOrder.OrderDate, - Buyer = GetBuyerEto(buyer), + Buyer = GetBuyerEto(order.Buyer), Items = GetProductItemEtoList(order.OrderItems) }); return placedOrder; } - public async Task AcceptOrderAsync(Guid orderId) + public async Task AcceptOrderAsync(Guid orderId, Guid paymentRequestId, string paymentRequestStatus) { var order = await _orderRepository.GetAsync(orderId); if (order == null) @@ -99,21 +87,17 @@ public class OrderManager : DomainService .WithData("OrderId", orderId); } - //Update order.PaymentId - //Update order.PaymentStatus - order.SetOrderPaid(); - - return await _orderRepository.UpdateAsync(order); + order.SetOrderAccepted(paymentRequestId, paymentRequestStatus); + return await _orderRepository.UpdateAsync(order, autoSave: true); } private BuyerEto GetBuyerEto(Buyer buyer) { - return new BuyerEto() + return new BuyerEto { BuyerEmail = buyer.Email, - BuyerId = buyer.Id, - PaymentType = buyer.PaymentType.Name, - PaymentTypeId = buyer.PaymentType.Id + BuyerName = buyer.Name, + BuyerId = buyer.Id }; } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/PaymentType.cs similarity index 100% rename from services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/PaymentType.cs rename to services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/PaymentType.cs diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs index 585eb993..a72f14e3 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs @@ -3,8 +3,8 @@ using EShopOnAbp.PaymentService.PaymentRequests; using System; using System.Linq; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.DependencyInjection; -using Volo.Abp.Domain.Repositories; using Volo.Abp.EventBus.Distributed; namespace EShopOnAbp.OrderingService.PaymentRequests @@ -13,22 +13,36 @@ namespace EShopOnAbp.OrderingService.PaymentRequests ITransientDependency { private readonly IDistributedEventBus _eventBus; + private readonly OrderManager _orderManager; - public PaymentRequestEventHandler(IDistributedEventBus eventBus) + public PaymentRequestEventHandler(IDistributedEventBus eventBus, OrderManager orderManager) { _eventBus = eventBus; + _orderManager = orderManager; } public async Task HandleEventAsync(PaymentRequestCompletedEto eventData) { - // TODO: Insert Order here. - //throw new NotImplementedException(); + if (!Guid.TryParse(eventData.OrderId, out var orderId)) + { + throw new BusinessException(OrderingServiceErrorCodes.OrderIdIdNotGuid); + } + + var acceptedOrder = await _orderManager.AcceptOrderAsync( + orderId, eventData.PaymentRequestId, eventData.State.ToString() + ); await _eventBus.PublishAsync(new OrderAcceptedEto { Items = eventData.Products.Select(MapProductToOrderItem).ToList(), - BuyerId = Guid.Parse(eventData.BuyerId), - OrderId = Guid.Empty, // TODO: Inserted OrderId, + PaymentStatus = acceptedOrder.PaymentStatus, + Buyer = new BuyerEto + { + BuyerId = acceptedOrder.Buyer.Id, + BuyerEmail = acceptedOrder.Buyer.Email, + BuyerName = acceptedOrder.Buyer.Name + }, + OrderId = acceptedOrder.Id }); } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs deleted file mode 100644 index aa56abcb..00000000 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using EShopOnAbp.OrderingService.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; -using Volo.Abp.Domain.Repositories.EntityFrameworkCore; -using Volo.Abp.EntityFrameworkCore; - -namespace EShopOnAbp.OrderingService.Buyers; - -public class EfCoreBuyerRepository : EfCoreRepository, IBuyerRepository -{ - public EfCoreBuyerRepository(IDbContextProvider dbContextProvider) : base( - dbContextProvider) - { - } - - public override async Task InsertAsync(Buyer entity, bool autoSave = false, - CancellationToken cancellationToken = new CancellationToken()) - { - var newEntity = await base.InsertAsync(entity, autoSave, cancellationToken); - await EnsurePropertyLoadedAsync(newEntity, query => query.PaymentType, cancellationToken); - return newEntity; - } - - public override async Task> WithDetailsAsync() - { - return (await GetQueryableAsync()) - .Include(q => q.PaymentType); - } -} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/IOrderingServiceDbContext.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/IOrderingServiceDbContext.cs index 79fd4625..7589800b 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/IOrderingServiceDbContext.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/IOrderingServiceDbContext.cs @@ -1,5 +1,4 @@ -using EShopOnAbp.OrderingService.Buyers; -using EShopOnAbp.OrderingService.Orders; +using EShopOnAbp.OrderingService.Orders; using Microsoft.EntityFrameworkCore; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; @@ -12,7 +11,6 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore /* Add DbSet for each Aggregate Root here. Example: * DbSet Questions { get; } */ - DbSet Buyers { get; } DbSet Orders { get; } } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs index 3d24451d..6b673f3c 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs @@ -11,7 +11,6 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore [ConnectionStringName(OrderingServiceDbProperties.ConnectionStringName)] public class OrderingServiceDbContext : AbpDbContext, IOrderingServiceDbContext { - public virtual DbSet Buyers { get; set; } public virtual DbSet Orders { get; set; } public OrderingServiceDbContext(DbContextOptions options) @@ -27,56 +26,48 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore builder.ConfigureOrderingService(); /* Configure your own tables/entities inside here */ - - builder.Entity(b => - { - b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "Buyers", OrderingServiceDbProperties.DbSchema); - b.ConfigureByConvention(); //auto configure for the base class props - - b.Property(q => q.Email).IsRequired(); - b.Property(q => q.Name).IsRequired(); - - b.Property("_paymentTypeId").UsePropertyAccessMode(PropertyAccessMode.Field) - .HasColumnName("PaymentTypeId") - .IsRequired(); - - b.HasOne(q => q.PaymentType).WithMany().HasForeignKey("_paymentTypeId"); - }); - builder.Entity(b => - { - b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "PaymentTypes", - OrderingServiceDbProperties.DbSchema); - b.ConfigureByConvention(); //auto configure for the base class props - - b.HasKey(q => q.Id); - b.Property(q => q.Id) - .HasDefaultValue(1) - .ValueGeneratedNever() - .IsRequired(); - b.Property(o => o.Name) - .HasMaxLength(OrderConstants.OrderPaymentTypeNameMaxLength) - .IsRequired(); - }); + builder.Entity(b => { b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "Orders", OrderingServiceDbProperties.DbSchema); b.ConfigureByConvention(); //auto configure for the base class props + + b.Property(q => q.PaymentStatus).HasMaxLength(OrderConstants.PaymentStatusMaxLength); + b.OwnsOne(o => o.Address, a => { a.WithOwner(); }); + b.OwnsOne(o => o.Buyer, a => { a.WithOwner(); }); + b.Property("_orderStatusId").UsePropertyAccessMode(PropertyAccessMode.Field) .HasColumnName("OrderStatusId") .IsRequired(); - b.Property(q => q.PaymentStatus).HasMaxLength(OrderConstants.PaymentStatusMaxLength); + + b.Property("_paymentTypeId").UsePropertyAccessMode(PropertyAccessMode.Field) + .HasColumnName("PaymentTypeId") + .IsRequired(); - b.HasOne().WithMany().HasForeignKey(q => q.BuyerId).IsRequired(false); b.HasOne(q => q.OrderStatus).WithMany().HasForeignKey("_orderStatusId"); + b.HasOne(q => q.PaymentType).WithMany().HasForeignKey("_paymentTypeId"); b.Navigation(q => q.OrderItems).UsePropertyAccessMode(PropertyAccessMode.Property); - - b.HasIndex(q => q.Id); - b.HasIndex(q => q.BuyerId); }); + builder.Entity(b => + { + b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "OrderItems", + OrderingServiceDbProperties.DbSchema); + b.ConfigureByConvention(); //auto configure for the base class props + + b.Property("OrderId").IsRequired(); + b.Property(q => q.ProductId).IsRequired(); + b.Property(q => q.ProductCode).IsRequired(); + b.Property(q => q.ProductName).IsRequired(); + b.Property(q => q.Discount).IsRequired(); + b.Property(q => q.UnitPrice).IsRequired(); + b.Property(q => q.Units).IsRequired(); + b.Property(q => q.PictureUrl).IsRequired(false); + }); + builder.Entity(b => { b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "OrderStatus", @@ -84,29 +75,33 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore b.ConfigureByConvention(); //auto configure for the base class props b.HasKey(q => q.Id); + b.Property(q => q.Id) .HasDefaultValue(1) .ValueGeneratedNever() .IsRequired(); + b.Property(o => o.Name) .HasMaxLength(OrderConstants.OrderStatusNameMaxLength) .IsRequired(); }); - - builder.Entity(b => + + builder.Entity(b => { - b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "OrderItems", + b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "PaymentTypes", OrderingServiceDbProperties.DbSchema); b.ConfigureByConvention(); //auto configure for the base class props - b.Property("OrderId").IsRequired(); - b.Property(q => q.ProductId).IsRequired(); - b.Property(q => q.ProductCode).IsRequired(); - b.Property(q => q.ProductName).IsRequired(); - b.Property(q => q.Discount).IsRequired(); - b.Property(q => q.UnitPrice).IsRequired(); - b.Property(q => q.Units).IsRequired(); - b.Property(q => q.PictureUrl).IsRequired(false); + b.HasKey(q => q.Id); + + b.Property(q => q.Id) + .HasDefaultValue(1) + .ValueGeneratedNever() + .IsRequired(); + + b.Property(o => o.Name) + .HasMaxLength(OrderConstants.OrderPaymentTypeNameMaxLength) + .IsRequired(); }); } } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104115822_Removed_Buyer_Domain.Designer.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104115822_Removed_Buyer_Domain.Designer.cs new file mode 100644 index 00000000..07d40a43 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104115822_Removed_Buyer_Domain.Designer.cs @@ -0,0 +1,230 @@ +// +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("20220104115822_Removed_Buyer_Domain")] + partial class Removed_Buyer_Domain + { + 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.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("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.Property("_paymentTypeId") + .HasColumnType("integer") + .HasColumnName("PaymentTypeId"); + + b.HasKey("Id"); + + b.HasIndex("_orderStatusId"); + + b.HasIndex("_paymentTypeId"); + + 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.Orders.Order", b => + { + b.HasOne("EShopOnAbp.OrderingService.Orders.OrderStatus", "OrderStatus") + .WithMany() + .HasForeignKey("_orderStatusId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EShopOnAbp.OrderingService.Buyers.PaymentType", "PaymentType") + .WithMany() + .HasForeignKey("_paymentTypeId") + .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.OwnsOne("EShopOnAbp.OrderingService.Orders.Buyer", "Buyer", b1 => + { + b1.Property("OrderId") + .HasColumnType("uuid"); + + b1.Property("Email") + .HasColumnType("text"); + + b1.Property("Id") + .HasColumnType("uuid"); + + b1.Property("Name") + .HasColumnType("text"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + + b.Navigation("Address"); + + b.Navigation("Buyer"); + + b.Navigation("OrderStatus"); + + b.Navigation("PaymentType"); + }); + + 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/20220104115822_Removed_Buyer_Domain.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104115822_Removed_Buyer_Domain.cs new file mode 100644 index 00000000..2671ec07 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220104115822_Removed_Buyer_Domain.cs @@ -0,0 +1,137 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EShopOnAbp.OrderingService.Migrations +{ + public partial class Removed_Buyer_Domain : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Buyers_BuyerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Buyers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_BuyerId", + table: "Orders"); + + migrationBuilder.DropIndex( + name: "IX_Orders_Id", + table: "Orders"); + + migrationBuilder.RenameColumn( + name: "BuyerId", + table: "Orders", + newName: "Buyer_Id"); + + migrationBuilder.AddColumn( + name: "Buyer_Email", + table: "Orders", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "Buyer_Name", + table: "Orders", + type: "text", + nullable: true); + + migrationBuilder.AddColumn( + name: "PaymentTypeId", + table: "Orders", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateIndex( + name: "IX_Orders_PaymentTypeId", + table: "Orders", + column: "PaymentTypeId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_PaymentTypes_PaymentTypeId", + table: "Orders", + column: "PaymentTypeId", + principalTable: "PaymentTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_PaymentTypes_PaymentTypeId", + table: "Orders"); + + migrationBuilder.DropIndex( + name: "IX_Orders_PaymentTypeId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "Buyer_Email", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "Buyer_Name", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "PaymentTypeId", + table: "Orders"); + + migrationBuilder.RenameColumn( + name: "Buyer_Id", + table: "Orders", + newName: "BuyerId"); + + migrationBuilder.CreateTable( + name: "Buyers", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + PaymentTypeId = table.Column(type: "integer", nullable: false), + ConcurrencyStamp = table.Column(type: "character varying(40)", maxLength: 40, nullable: true), + Email = table.Column(type: "text", nullable: false), + ExtraProperties = table.Column(type: "text", nullable: true), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Buyers", x => x.Id); + table.ForeignKey( + name: "FK_Buyers_PaymentTypes_PaymentTypeId", + column: x => x.PaymentTypeId, + principalTable: "PaymentTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_BuyerId", + table: "Orders", + column: "BuyerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_Id", + table: "Orders", + column: "Id"); + + migrationBuilder.CreateIndex( + name: "IX_Buyers_PaymentTypeId", + table: "Buyers", + column: "PaymentTypeId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Buyers_BuyerId", + table: "Orders", + column: "BuyerId", + principalTable: "Buyers", + principalColumn: "Id"); + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs index 3d7badcc..79591235 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -24,40 +24,6 @@ namespace EShopOnAbp.OrderingService.Migrations 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") @@ -79,9 +45,6 @@ namespace EShopOnAbp.OrderingService.Migrations b.Property("Id") .HasColumnType("uuid"); - b.Property("BuyerId") - .HasColumnType("uuid"); - b.Property("ConcurrencyStamp") .IsConcurrencyToken() .HasMaxLength(40) @@ -106,14 +69,16 @@ namespace EShopOnAbp.OrderingService.Migrations .HasColumnType("integer") .HasColumnName("OrderStatusId"); - b.HasKey("Id"); - - b.HasIndex("BuyerId"); + b.Property("_paymentTypeId") + .HasColumnType("integer") + .HasColumnName("PaymentTypeId"); - b.HasIndex("Id"); + b.HasKey("Id"); b.HasIndex("_orderStatusId"); + b.HasIndex("_paymentTypeId"); + b.ToTable("Orders", (string)null); }); @@ -171,26 +136,17 @@ namespace EShopOnAbp.OrderingService.Migrations b.ToTable("OrderStatus", (string)null); }); - modelBuilder.Entity("EShopOnAbp.OrderingService.Buyers.Buyer", b => + modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => { - b.HasOne("EShopOnAbp.OrderingService.Buyers.PaymentType", "PaymentType") + b.HasOne("EShopOnAbp.OrderingService.Orders.OrderStatus", "OrderStatus") .WithMany() - .HasForeignKey("_paymentTypeId") + .HasForeignKey("_orderStatusId") .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") + b.HasOne("EShopOnAbp.OrderingService.Buyers.PaymentType", "PaymentType") .WithMany() - .HasForeignKey("_orderStatusId") + .HasForeignKey("_paymentTypeId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -222,9 +178,35 @@ namespace EShopOnAbp.OrderingService.Migrations .HasForeignKey("OrderId"); }); + b.OwnsOne("EShopOnAbp.OrderingService.Orders.Buyer", "Buyer", b1 => + { + b1.Property("OrderId") + .HasColumnType("uuid"); + + b1.Property("Email") + .HasColumnType("text"); + + b1.Property("Id") + .HasColumnType("uuid"); + + b1.Property("Name") + .HasColumnType("text"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + b.Navigation("Address"); + b.Navigation("Buyer"); + b.Navigation("OrderStatus"); + + b.Navigation("PaymentType"); }); modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs index d63ef3cd..8d13116d 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs @@ -17,16 +17,18 @@ public class EfCoreOrderRepository : EfCoreRepository InsertAsync(Order entity, bool autoSave = false, - CancellationToken cancellationToken = new CancellationToken()) + CancellationToken cancellationToken = default) { - var newEntity = await base.InsertAsync(entity, autoSave, cancellationToken); - await EnsurePropertyLoadedAsync(newEntity, o => o.OrderStatus, cancellationToken); + var newEntity = await base.InsertAsync(entity, autoSave, GetCancellationToken(cancellationToken)); + await EnsurePropertyLoadedAsync(newEntity, o => o.OrderStatus, GetCancellationToken(cancellationToken)); + await EnsurePropertyLoadedAsync(newEntity, o => o.PaymentType, GetCancellationToken(cancellationToken)); return newEntity; } public override async Task> WithDetailsAsync() { return (await GetQueryableAsync()) - .Include(q => q.OrderStatus); + .Include(q => q.OrderStatus) + .Include(q => q.PaymentType); } } \ No newline at end of file