Browse Source

Merge pull request #49 from abpframework/gterdem/ordering

Create Aggregate roots and db configurations for OrderService
pull/51/head
Enis Necipoglu 4 years ago
committed by GitHub
parent
commit
a6fe9ff16c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      services/catalog/src/EShopOnAbp.CatalogService.Domain/OrderHandler.cs
  2. 70
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Enumeration.cs
  3. 6
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json
  4. 6
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json
  5. 6
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs
  6. 7
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderConstants.cs
  7. 4
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderItemEto.cs
  8. 24
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Buyers/Buyer.cs
  9. 35
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Address.cs
  10. 58
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs
  11. 58
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderItem.cs
  12. 51
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderStatus.cs
  13. 80
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/EntityFrameworkCore/OrderingServiceDbContext.cs
  14. 215
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211228131200_Added_Order_and_Buyer_Aggregates.Designer.cs
  15. 134
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211228131200_Added_Order_and_Buyer_Aggregates.cs
  16. 185
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs

1
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;

70
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<T> GetAll<T>() where T : Enumeration =>
typeof(T).GetFields(BindingFlags.Public |
BindingFlags.Static |
BindingFlags.DeclaredOnly)
.Select(f => f.GetValue(null))
.Cast<T>();
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<T>(int value) where T : Enumeration
{
var matchingItem = Parse<T, int>(value, "value", item => item.Id == value);
return matchingItem;
}
public static T FromDisplayName<T>(string displayName) where T : Enumeration
{
var matchingItem = Parse<T, string>(displayName, "display name", item => item.Name == displayName);
return matchingItem;
}
private static T Parse<T, K>(K value, string description, Func<T, bool> predicate) where T : Enumeration
{
var matchingItem = GetAll<T>().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);
}

6
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"
}
}

6
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"
}
}

6
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";
}
}

7
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;
}

4
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
{

24
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<Guid>
{
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));
}
}

35
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<object> GetAtomicValues()
{
yield return Street;
yield return City;
yield return Description;
yield return Country;
yield return ZipCode;
}
}

58
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<Guid>
{
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<OrderItem> 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<OrderItem>();
}
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);
}
}

58
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<Guid>
{
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;
}
}

51
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<OrderStatus> 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;
}
}

80
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<OrderingServiceDbContext>
{
public virtual DbSet<Buyer> Buyers { get; set; }
public virtual DbSet<Order> Orders { get; set; }
public OrderingServiceDbContext(DbContextOptions<OrderingServiceDbContext> 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<YourEntity>(b =>
//{
// b.ToTable(OrderingServiceConsts.DbTablePrefix + "YourEntities", OrderingServiceConsts.DbSchema);
// b.ConfigureByConvention(); //auto configure for the base class props
// //...
//});
builder.Entity<Buyer>(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<Order>(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<int>("_orderStatusId").UsePropertyAccessMode(PropertyAccessMode.Field)
.HasColumnName("OrderStatusId")
.IsRequired();
b.Property(q => q.Description).HasMaxLength(OrderConstants.OrderDescriptionMaxLength).IsRequired(false);
b.HasOne<Buyer>().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<OrderStatus>(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<OrderItem>(b =>
{
b.ToTable(OrderingServiceDbProperties.DbTablePrefix + "OrderItems",
OrderingServiceDbProperties.DbSchema);
b.ConfigureByConvention(); //auto configure for the base class props
b.Property<Guid>("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);
});
}
}
}
}

215
services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20211228131200_Added_Order_and_Buyer_Aggregates.Designer.cs

@ -0,0 +1,215 @@
// <auto-generated />
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<Guid>("Id")
.HasColumnType("uuid");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("character varying(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<string>("ExtraProperties")
.HasColumnType("text")
.HasColumnName("ExtraProperties");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PaymentId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Buyers", (string)null);
});
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uuid");
b.Property<Guid?>("BuyerId")
.HasColumnType("uuid");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("character varying(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<string>("Description")
.HasMaxLength(1024)
.HasColumnType("character varying(1024)");
b.Property<string>("ExtraProperties")
.HasColumnType("text")
.HasColumnName("ExtraProperties");
b.Property<DateTime>("OrderDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("PaymentMethodToken")
.HasColumnType("text");
b.Property<int>("_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<Guid>("Id")
.HasColumnType("uuid");
b.Property<decimal>("Discount")
.HasColumnType("numeric");
b.Property<Guid>("OrderId")
.HasColumnType("uuid");
b.Property<string>("PictureUrl")
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
b.Property<decimal>("UnitPrice")
.HasColumnType("numeric");
b.Property<int>("Units")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("OrderId");
b.ToTable("OrderItems", (string)null);
});
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderStatus", b =>
{
b.Property<int>("Id")
.HasColumnType("integer")
.HasDefaultValue(1);
b.Property<string>("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<Guid>("OrderId")
.HasColumnType("uuid");
b1.Property<string>("City")
.HasColumnType("text");
b1.Property<string>("Country")
.HasColumnType("text");
b1.Property<string>("Description")
.HasColumnType("text");
b1.Property<string>("Street")
.HasColumnType("text");
b1.Property<string>("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
}
}
}

134
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<Guid>(type: "uuid", nullable: false),
UserName = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
PaymentId = table.Column<string>(type: "text", nullable: false),
ExtraProperties = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(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<int>(type: "integer", nullable: false, defaultValue: 1),
Name = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
OrderDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
BuyerId = table.Column<Guid>(type: "uuid", nullable: true),
Description = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: true),
PaymentMethodToken = table.Column<string>(type: "text", nullable: true),
Address_Description = table.Column<string>(type: "text", nullable: true),
Address_Street = table.Column<string>(type: "text", nullable: true),
Address_City = table.Column<string>(type: "text", nullable: true),
Address_Country = table.Column<string>(type: "text", nullable: true),
Address_ZipCode = table.Column<string>(type: "text", nullable: true),
OrderStatusId = table.Column<int>(type: "integer", nullable: false),
ExtraProperties = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
ProductName = table.Column<string>(type: "text", nullable: false),
PictureUrl = table.Column<string>(type: "text", nullable: true),
UnitPrice = table.Column<decimal>(type: "numeric", nullable: false),
Discount = table.Column<decimal>(type: "numeric", nullable: false),
Units = table.Column<int>(type: "integer", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
OrderId = table.Column<Guid>(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");
}
}
}

185
services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs

@ -1,4 +1,5 @@
// <auto-generated />
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<Guid>("Id")
.HasColumnType("uuid");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("character varying(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<string>("ExtraProperties")
.HasColumnType("text")
.HasColumnName("ExtraProperties");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PaymentId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Buyers", (string)null);
});
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uuid");
b.Property<Guid?>("BuyerId")
.HasColumnType("uuid");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("character varying(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<string>("Description")
.HasMaxLength(1024)
.HasColumnType("character varying(1024)");
b.Property<string>("ExtraProperties")
.HasColumnType("text")
.HasColumnName("ExtraProperties");
b.Property<DateTime>("OrderDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("PaymentMethodToken")
.HasColumnType("text");
b.Property<int>("_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<Guid>("Id")
.HasColumnType("uuid");
b.Property<decimal>("Discount")
.HasColumnType("numeric");
b.Property<Guid>("OrderId")
.HasColumnType("uuid");
b.Property<string>("PictureUrl")
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
b.Property<decimal>("UnitPrice")
.HasColumnType("numeric");
b.Property<int>("Units")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("OrderId");
b.ToTable("OrderItems", (string)null);
});
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderStatus", b =>
{
b.Property<int>("Id")
.HasColumnType("integer")
.HasDefaultValue(1);
b.Property<string>("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<Guid>("OrderId")
.HasColumnType("uuid");
b1.Property<string>("City")
.HasColumnType("text");
b1.Property<string>("Country")
.HasColumnType("text");
b1.Property<string>("Description")
.HasColumnType("text");
b1.Property<string>("Street")
.HasColumnType("text");
b1.Property<string>("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
}
}

Loading…
Cancel
Save