diff --git a/services/catalog/src/EShopOnAbp.CatalogService.Domain/OrderHandler.cs b/services/catalog/src/EShopOnAbp.CatalogService.Domain/OrderHandler.cs index 1dabcc8e..0d3b8d58 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.Domain/OrderHandler.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.Domain/OrderHandler.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using EShopOnAbp.BasketService; using EShopOnAbp.CatalogService.Products; using EShopOnAbp.OrderingService.Orders; using Volo.Abp.DependencyInjection; diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Enumeration.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Enumeration.cs new file mode 100644 index 00000000..a4a351b3 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Enumeration.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace EShopOnAbp.OrderingService; + +// https://github.com/dotnet-architecture/eShopOnContainers/blob/dev/src/Services/Ordering/Ordering.Domain/SeedWork/Enumeration.cs +public abstract class Enumeration : IComparable +{ + public string Name { get; private set; } + + public int Id { get; private set; } + + protected Enumeration(int id, string name) => (Id, Name) = (id, name); + + public override string ToString() => Name; + + public static IEnumerable GetAll() where T : Enumeration => + typeof(T).GetFields(BindingFlags.Public | + BindingFlags.Static | + BindingFlags.DeclaredOnly) + .Select(f => f.GetValue(null)) + .Cast(); + + public override bool Equals(object obj) + { + if (obj is not Enumeration otherValue) + { + return false; + } + + var typeMatches = GetType().Equals(obj.GetType()); + var valueMatches = Id.Equals(otherValue.Id); + + return typeMatches && valueMatches; + } + + public override int GetHashCode() => Id.GetHashCode(); + + public static int AbsoluteDifference(Enumeration firstValue, Enumeration secondValue) + { + var absoluteDifference = Math.Abs(firstValue.Id - secondValue.Id); + return absoluteDifference; + } + + public static T FromValue(int value) where T : Enumeration + { + var matchingItem = Parse(value, "value", item => item.Id == value); + return matchingItem; + } + + public static T FromDisplayName(string displayName) where T : Enumeration + { + var matchingItem = Parse(displayName, "display name", item => item.Name == displayName); + return matchingItem; + } + + private static T Parse(K value, string description, Func predicate) where T : Enumeration + { + var matchingItem = GetAll().FirstOrDefault(predicate); + + if (matchingItem == null) + throw new InvalidOperationException($"'{value}' is not a valid {description} in {typeof(T)}"); + + return matchingItem; + } + + public int CompareTo(object other) => Id.CompareTo(((Enumeration) other).Id); +} \ No newline at end of file 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 7ab4c6d7..b4ba5394 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 @@ -2,6 +2,10 @@ "culture": "en", "texts": { "MyAccount": "My account", - "SamplePageMessage": "A sample page for the OrderingService module" + "SamplePageMessage": "A sample page for the OrderingService module", + "Ordering:00001": "Possible values for Order status: {0}", + "Ordering:00002": "Invalid number of units", + "Ordering:00003": "Invalid discount", + "Ordering:00004": "The total of order item is lower than applied discount" } } \ 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 07159dad..eadfdc27 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 @@ -2,6 +2,10 @@ "culture": "tr", "texts": { "MyAccount": "Hesabım", - "SamplePageMessage": "OrderingService modulünden örnek bir sayfa" + "SamplePageMessage": "OrderingService modulünden örnek bir sayfa", + "Ordering:00001": "Muhtemel Sipariş durum değerleri: {0}", + "Ordering:00002": "Ürün adedi negatif olamaz", + "Ordering:00003": "Geçersiz indirim", + "Ordering:00004": "Ürünlerin toplam bedeli, uygulanan indirimden daha az olamaz" } } \ 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 dae0f837..b520db67 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs @@ -2,6 +2,10 @@ { public static class OrderingServiceErrorCodes { - //Add your business exception error codes here... + public const string OrderingStatusNotFound = "Ordering:00001"; + 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.Shared/Orders/OrderConstants.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs new file mode 100644 index 00000000..1cff526c --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs @@ -0,0 +1,7 @@ +namespace EShopOnAbp.OrderingService.Orders; + +public static class OrderConstants +{ + public const int OrderDescriptionMaxLength = 1024; + public const int OrderStatusNameMaxLength = 256; +} \ 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 367baffd..5249e452 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderItemEto.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderItemEto.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EShopOnAbp.OrderingService.Orders { diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs new file mode 100644 index 00000000..d6727646 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs @@ -0,0 +1,24 @@ +using System; +using JetBrains.Annotations; +using Volo.Abp; +using Volo.Abp.Domain.Entities; + +namespace EShopOnAbp.OrderingService.Buyers; + +public class Buyer : AggregateRoot +{ + public string UserName { get; private set; } + public string Name { get; private set; } + public string PaymentId { get; private set; } + + private Buyer() + { + } + + public Buyer(Guid id, [NotNull] string userName, [NotNull] string name, [NotNull] string paymentId) : base(id) + { + UserName = Check.NotNullOrEmpty(userName, nameof(userName)); + Name = Check.NotNullOrEmpty(name, nameof(name)); + PaymentId = Check.NotNullOrEmpty(paymentId, nameof(paymentId)); + } +} \ 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 new file mode 100644 index 00000000..1de9d0fb --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Address.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using Volo.Abp.Domain.Values; + +namespace EShopOnAbp.OrderingService.Orders; + +public class Address : ValueObject +{ + public string Description { get; private set; } + public string Street { get; private set; } + public string City { get; private set; } + public string Country { get; private set; } + public string ZipCode { get; private set; } + + private Address() + { + } + + public Address(string street, string city, string description, string country, string zipcode) + { + Street = street; + City = city; + 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; + } +} \ 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 new file mode 100644 index 00000000..3867875a --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Volo.Abp.Domain.Entities; + +namespace EShopOnAbp.OrderingService.Orders; + +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 Address Address { get; private set; } + public OrderStatus OrderStatus { get; private set; } + public List OrderItems { get; private set; } + + private Order() + { + } + + public Order(Guid id, Address address, Guid? buyerId = null, string paymentMethodToken = null) : base() + { + _orderStatusId = OrderStatus.Submitted.Id; + OrderDate = DateTime.UtcNow; + Address = address; + BuyerId = buyerId; + PaymentMethodToken = paymentMethodToken; + OrderItems = new List(); + } + + public void AddOrderItem(Guid productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, + int units = 1) + { + var existingOrderForProduct = OrderItems.SingleOrDefault(o => o.ProductId == productId); + + if (existingOrderForProduct != null) + { + if (discount > existingOrderForProduct.Discount) + { + existingOrderForProduct.SetNewDiscount(discount); + } + + existingOrderForProduct.AddUnits(units); + } + else + { + var orderItem = new OrderItem(productId, productName, unitPrice, discount, pictureUrl, units); + OrderItems.Add(orderItem); + } + } + + public decimal GetTotal() + { + return OrderItems.Sum(o => o.Units * o.UnitPrice); + } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs new file mode 100644 index 00000000..4c571174 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs @@ -0,0 +1,58 @@ +using System; +using JetBrains.Annotations; +using Volo.Abp; +using Volo.Abp.Domain.Entities; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderItem : Entity +{ + public string ProductName { get; private set; } + public string PictureUrl { get; private set; } + public decimal UnitPrice { get; private set; } + public decimal Discount { get; private set; } + public int Units { get; private set; } + public Guid ProductId { get; private set; } + + protected OrderItem() { } + + public OrderItem(Guid productId, [NotNull]string productName, decimal unitPrice, decimal discount, [CanBeNull]string pictureUrl, int units = 1) + { + if (units <= 0) + { + throw new BusinessException(OrderingServiceErrorCodes.InvalidUnits); + } + + if ((unitPrice * units) < discount) + { + throw new BusinessException(OrderingServiceErrorCodes.InvalidTotalForDiscount); + } + + ProductId = productId; + ProductName = Check.NotNullOrEmpty(productName, nameof(productName)); + UnitPrice = unitPrice; + Discount = discount; + Units = units; + PictureUrl = pictureUrl; + } + + public void SetNewDiscount(decimal discount) + { + if (discount < 0) + { + throw new BusinessException(OrderingServiceErrorCodes.InvalidDiscount); + } + + Discount = discount; + } + + public void AddUnits(int units) + { + if (units < 0) + { + throw new BusinessException(OrderingServiceErrorCodes.InvalidUnits); + } + + Units += units; + } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs new file mode 100644 index 00000000..676fe3ae --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Volo.Abp; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderStatus: Enumeration +{ + public static OrderStatus Submitted = new OrderStatus(1, nameof(Submitted).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()); + public static OrderStatus Shipped = new OrderStatus(5, nameof(Shipped).ToLowerInvariant()); + public static OrderStatus Cancelled = new OrderStatus(6, nameof(Cancelled).ToLowerInvariant()); + + public OrderStatus(int id, string name) + : base(id, name) + { + } + + public static IEnumerable List() => + new[] { Submitted, AwaitingValidation, StockConfirmed, Paid, Shipped, Cancelled }; + + public static OrderStatus FromName(string name) + { + var state = List() + .SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); + + if (state == null) + { + throw new BusinessException(OrderingServiceErrorCodes.OrderingStatusNotFound) + .WithData("OrderStatus", String.Join(",", List().Select(s => s.Name))); + } + + return state; + } + + public static OrderStatus From(int id) + { + var state = List().SingleOrDefault(s => s.Id == id); + + if (state == null) + { + throw new BusinessException(OrderingServiceErrorCodes.OrderingStatusNotFound) + .WithData("OrderStatus", String.Join(",", List().Select(s => s.Name))); + } + + return state; + } +} \ 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 dbcb0c7a..21006f56 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs @@ -1,6 +1,10 @@ -using Microsoft.EntityFrameworkCore; +using System; +using EShopOnAbp.OrderingService.Buyers; +using EShopOnAbp.OrderingService.Orders; +using Microsoft.EntityFrameworkCore; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore.Modeling; namespace EShopOnAbp.OrderingService.EntityFrameworkCore { @@ -8,10 +12,12 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore public class OrderingServiceDbContext : AbpDbContext { + public virtual DbSet Buyers { get; set; } + public virtual DbSet Orders { get; set; } + public OrderingServiceDbContext(DbContextOptions options) : base(options) { - } protected override void OnModelCreating(ModelBuilder builder) @@ -23,12 +29,68 @@ namespace EShopOnAbp.OrderingService.EntityFrameworkCore builder.ConfigureOrderingService(); /* Configure your own tables/entities inside here */ - //builder.Entity(b => - //{ - // b.ToTable(OrderingServiceConsts.DbTablePrefix + "YourEntities", OrderingServiceConsts.DbSchema); - // b.ConfigureByConvention(); //auto configure for the base class props - // //... - //}); + builder.Entity(b => + { + 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.Name).IsRequired(); + b.Property(q => q.PaymentId).IsRequired(); + }); + + builder.Entity(b => + { + b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "Orders", OrderingServiceDbProperties.DbSchema); + b.ConfigureByConvention(); //auto configure for the base class props + b.OwnsOne(o => o.Address, a => + { + a.WithOwner(); + }); + 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"); + + b.Navigation(q => q.OrderItems).UsePropertyAccessMode(PropertyAccessMode.Property); + + 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", + 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.OrderStatusNameMaxLength) + .IsRequired(); + }); + + 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.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); + }); } } -} +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211228131200_Added_Order_and_Buyer_Aggregates.Designer.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211228131200_Added_Order_and_Buyer_Aggregates.Designer.cs new file mode 100644 index 00000000..88bbfbcd --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211228131200_Added_Order_and_Buyer_Aggregates.Designer.cs @@ -0,0 +1,215 @@ +// +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("20211228131200_Added_Order_and_Buyer_Aggregates")] + partial class Added_Order_and_Buyer_Aggregates + { + 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("ExtraProperties") + .HasColumnType("text") + .HasColumnName("ExtraProperties"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("PaymentId") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Buyers", (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("Description") + .HasMaxLength(1024) + .HasColumnType("character varying(1024)"); + + 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.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/20211228131200_Added_Order_and_Buyer_Aggregates.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211228131200_Added_Order_and_Buyer_Aggregates.cs new file mode 100644 index 00000000..817dd7ae --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211228131200_Added_Order_and_Buyer_Aggregates.cs @@ -0,0 +1,134 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EShopOnAbp.OrderingService.Migrations +{ + public partial class Added_Order_and_Buyer_Aggregates : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Buyers", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + UserName = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + PaymentId = table.Column(type: "text", nullable: false), + ExtraProperties = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "character varying(40)", maxLength: 40, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Buyers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "OrderStatus", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false, defaultValue: 1), + Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderStatus", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + OrderDate = table.Column(type: "timestamp with time zone", nullable: false), + BuyerId = table.Column(type: "uuid", nullable: true), + Description = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true), + PaymentMethodToken = table.Column(type: "text", nullable: true), + Address_Description = table.Column(type: "text", nullable: true), + Address_Street = table.Column(type: "text", nullable: true), + Address_City = table.Column(type: "text", nullable: true), + Address_Country = table.Column(type: "text", nullable: true), + Address_ZipCode = table.Column(type: "text", nullable: true), + OrderStatusId = table.Column(type: "integer", nullable: false), + ExtraProperties = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "character varying(40)", maxLength: 40, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Buyers_BuyerId", + column: x => x.BuyerId, + principalTable: "Buyers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Orders_OrderStatus_OrderStatusId", + column: x => x.OrderStatusId, + principalTable: "OrderStatus", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OrderItems", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + ProductName = table.Column(type: "text", nullable: false), + PictureUrl = table.Column(type: "text", nullable: true), + UnitPrice = table.Column(type: "numeric", nullable: false), + Discount = table.Column(type: "numeric", nullable: false), + Units = table.Column(type: "integer", nullable: false), + ProductId = table.Column(type: "uuid", nullable: false), + OrderId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderItems", x => x.Id); + table.ForeignKey( + name: "FK_OrderItems_Orders_OrderId", + column: x => x.OrderId, + principalTable: "Orders", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_OrderItems_OrderId", + table: "OrderItems", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_BuyerId", + table: "Orders", + column: "BuyerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_Id", + table: "Orders", + column: "Id"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_OrderStatusId", + table: "Orders", + column: "OrderStatusId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "OrderItems"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Buyers"); + + migrationBuilder.DropTable( + name: "OrderStatus"); + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs index 727a995f..14f7bd8a 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -1,4 +1,5 @@ // +using System; using EShopOnAbp.OrderingService.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -22,6 +23,190 @@ namespace EShopOnAbp.OrderingService.Migrations .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("ExtraProperties") + .HasColumnType("text") + .HasColumnName("ExtraProperties"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("PaymentId") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Buyers", (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("Description") + .HasMaxLength(1024) + .HasColumnType("character varying(1024)"); + + 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.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 } }