diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs index 9a899c46..989208a0 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using EShopOnAbp.PaymentService.PaymentRequests; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Entities; namespace EShopOnAbp.OrderingService.Orders; @@ -22,8 +25,7 @@ public class Order : AggregateRoot { } - internal Order(Guid id, Buyer buyer, Address address, string paymentMethod, - Guid? paymentRequestId = null) : base(id) + internal Order(Guid id, Buyer buyer, Address address, [NotNull]string paymentMethod, Guid? paymentRequestId = null) : base(id) { _orderStatusId = OrderStatus.Placed.Id; OrderDate = DateTime.UtcNow; @@ -31,8 +33,8 @@ public class Order : AggregateRoot Buyer = buyer; Address = address; PaymentRequestId = paymentRequestId; - PaymentMethod = paymentMethod; - PaymentStatus = "Waiting"; // TODO: magic string + PaymentMethod = Check.NotNullOrEmpty(paymentMethod,nameof(paymentMethod),maxLength:OrderConstants.OrderPaymentMethodNameMaxLength); + PaymentStatus = PaymentRequestState.Waiting.ToString(); // From PaymentService.Domain.Shared OrderItems = new List(); } diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs index 8958a97b..d4b2d864 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs @@ -33,7 +33,7 @@ public class OrderingServiceDbContext : AbpDbContext, b.ConfigureByConvention(); //auto configure for the base class props b.Property(q => q.PaymentStatus).HasMaxLength(OrderConstants.PaymentStatusMaxLength); - b.Property(q => q.PaymentMethod).HasMaxLength(OrderConstants.OrderPaymentMethodNameMaxLength); + b.Property(q => q.PaymentMethod).HasMaxLength(OrderConstants.OrderPaymentMethodNameMaxLength).IsRequired(); b.OwnsOne(o => o.Address, a => { a.WithOwner(); }); b.OwnsOne(o => o.Buyer, a => { a.WithOwner(); }); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118092211_PaymentMethod_IsRequired.Designer.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118092211_PaymentMethod_IsRequired.Designer.cs new file mode 100644 index 00000000..75d459f8 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118092211_PaymentMethod_IsRequired.Designer.cs @@ -0,0 +1,208 @@ +// +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("20220118092211_PaymentMethod_IsRequired")] + partial class PaymentMethod_IsRequired + { + 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.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("OrderNo") + .HasColumnType("integer"); + + b.Property("PaymentMethod") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + 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("_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.Orders.Order", b => + { + 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.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"); + }); + + 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/20220118092211_PaymentMethod_IsRequired.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118092211_PaymentMethod_IsRequired.cs new file mode 100644 index 00000000..e1d295ab --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220118092211_PaymentMethod_IsRequired.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EShopOnAbp.OrderingService.Migrations +{ + public partial class PaymentMethod_IsRequired : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "PaymentMethod", + table: "Orders", + type: "character varying(128)", + maxLength: 128, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "character varying(128)", + oldMaxLength: 128, + oldNullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "PaymentMethod", + table: "Orders", + type: "character varying(128)", + maxLength: 128, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(128)", + oldMaxLength: 128); + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs index 59c5af1f..2b0060f2 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -46,6 +46,7 @@ namespace EShopOnAbp.OrderingService.Migrations .HasColumnType("integer"); b.Property("PaymentMethod") + .IsRequired() .HasMaxLength(128) .HasColumnType("character varying(128)");