Browse Source
After implementing discussion-enum branch, need to merge main branch into this branch and solved conflict regarding OrderStatus and updating data.pull/92/head
13 changed files with 297 additions and 184 deletions
@ -0,0 +1,9 @@ |
|||||
|
namespace EShopOnAbp.OrderingService.Orders; |
||||
|
|
||||
|
public enum OrderStatus |
||||
|
{ |
||||
|
Placed, |
||||
|
Paid, |
||||
|
Shipped, |
||||
|
Cancelled |
||||
|
} |
||||
@ -1,49 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using Volo.Abp; |
|
||||
|
|
||||
namespace EShopOnAbp.OrderingService.Orders; |
|
||||
|
|
||||
//TODO will use enum instead of Enumeration
|
|
||||
public class OrderStatus : Enumeration |
|
||||
{ |
|
||||
public static OrderStatus Placed = new OrderStatus(1, nameof(Placed).ToLowerInvariant()); |
|
||||
public static OrderStatus Paid = new OrderStatus(2, nameof(Paid).ToLowerInvariant()); |
|
||||
public static OrderStatus Shipped = new OrderStatus(3, nameof(Shipped).ToLowerInvariant()); |
|
||||
public static OrderStatus Cancelled = new OrderStatus(4, nameof(Cancelled).ToLowerInvariant()); |
|
||||
|
|
||||
public OrderStatus(int id, string name) : base(id, name) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public static IEnumerable<OrderStatus> List() => |
|
||||
new[] {Placed, 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; |
|
||||
} |
|
||||
} |
|
||||
@ -1,37 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using System.Threading.Tasks; |
|
||||
using EShopOnAbp.OrderingService.Orders; |
|
||||
using Microsoft.EntityFrameworkCore; |
|
||||
using Volo.Abp.Data; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
|
|
||||
namespace EShopOnAbp.OrderingService.EntityFrameworkCore; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// DataSeedContributor for seeding pre-exist order status data.
|
|
||||
/// This is a sample for seeding data without DbSet (non-aggregate data), without using repository.
|
|
||||
/// </summary>
|
|
||||
public class OrderServiceDataSeedContributor : IDataSeedContributor, ITransientDependency |
|
||||
{ |
|
||||
private readonly IOrderingServiceDbContext _dbContext; |
|
||||
|
|
||||
public OrderServiceDataSeedContributor(IOrderingServiceDbContext dbContext) |
|
||||
{ |
|
||||
_dbContext = dbContext; |
|
||||
} |
|
||||
|
|
||||
public async Task SeedAsync(DataSeedContext context) |
|
||||
{ |
|
||||
await SeedOrderStatusAsync(); |
|
||||
} |
|
||||
|
|
||||
private async Task SeedOrderStatusAsync() |
|
||||
{ |
|
||||
if (!await _dbContext.Set<OrderStatus>().AnyAsync()) |
|
||||
{ |
|
||||
await _dbContext.Set<OrderStatus>().AddRangeAsync(OrderStatus.List()); |
|
||||
await _dbContext.SaveChangesAsync(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,182 @@ |
|||||
|
// <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("20220317123922_RemovedOrderStatusTable")] |
||||
|
partial class RemovedOrderStatusTable |
||||
|
{ |
||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
||||
|
{ |
||||
|
#pragma warning disable 612, 618
|
||||
|
modelBuilder |
||||
|
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql) |
||||
|
.HasAnnotation("ProductVersion", "6.0.1") |
||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63); |
||||
|
|
||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
||||
|
|
||||
|
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", 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<DateTime>("OrderDate") |
||||
|
.HasColumnType("timestamp without time zone"); |
||||
|
|
||||
|
b.Property<int>("OrderNo") |
||||
|
.HasColumnType("integer"); |
||||
|
|
||||
|
b.Property<string>("OrderStatus") |
||||
|
.IsRequired() |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b.Property<string>("PaymentMethod") |
||||
|
.IsRequired() |
||||
|
.HasMaxLength(128) |
||||
|
.HasColumnType("character varying(128)"); |
||||
|
|
||||
|
b.Property<Guid?>("PaymentRequestId") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b.Property<string>("PaymentStatus") |
||||
|
.HasMaxLength(256) |
||||
|
.HasColumnType("character varying(256)"); |
||||
|
|
||||
|
b.HasKey("Id"); |
||||
|
|
||||
|
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<string>("ProductCode") |
||||
|
.IsRequired() |
||||
|
.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.Order", b => |
||||
|
{ |
||||
|
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.OwnsOne("EShopOnAbp.OrderingService.Orders.Buyer", "Buyer", b1 => |
||||
|
{ |
||||
|
b1.Property<Guid>("OrderId") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b1.Property<string>("Email") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b1.Property<Guid?>("Id") |
||||
|
.HasColumnType("uuid"); |
||||
|
|
||||
|
b1.Property<string>("Name") |
||||
|
.HasColumnType("text"); |
||||
|
|
||||
|
b1.HasKey("OrderId"); |
||||
|
|
||||
|
b1.ToTable("Orders"); |
||||
|
|
||||
|
b1.WithOwner() |
||||
|
.HasForeignKey("OrderId"); |
||||
|
}); |
||||
|
|
||||
|
b.Navigation("Address"); |
||||
|
|
||||
|
b.Navigation("Buyer"); |
||||
|
}); |
||||
|
|
||||
|
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
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
|
||||
|
#nullable disable |
||||
|
|
||||
|
namespace EShopOnAbp.OrderingService.Migrations |
||||
|
{ |
||||
|
public partial class RemovedOrderStatusTable : Migration |
||||
|
{ |
||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropForeignKey( |
||||
|
name: "FK_Orders_OrderStatus_OrderStatusId", |
||||
|
table: "Orders"); |
||||
|
|
||||
|
migrationBuilder.DropTable( |
||||
|
name: "OrderStatus"); |
||||
|
|
||||
|
migrationBuilder.DropIndex( |
||||
|
name: "IX_Orders_OrderStatusId", |
||||
|
table: "Orders"); |
||||
|
|
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "OrderStatusId", |
||||
|
table: "Orders"); |
||||
|
|
||||
|
migrationBuilder.AddColumn<string>( |
||||
|
name: "OrderStatus", |
||||
|
table: "Orders", |
||||
|
type: "text", |
||||
|
nullable: false, |
||||
|
defaultValue: ""); |
||||
|
} |
||||
|
|
||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "OrderStatus", |
||||
|
table: "Orders"); |
||||
|
|
||||
|
migrationBuilder.AddColumn<int>( |
||||
|
name: "OrderStatusId", |
||||
|
table: "Orders", |
||||
|
type: "integer", |
||||
|
nullable: false, |
||||
|
defaultValue: 0); |
||||
|
|
||||
|
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.CreateIndex( |
||||
|
name: "IX_Orders_OrderStatusId", |
||||
|
table: "Orders", |
||||
|
column: "OrderStatusId"); |
||||
|
|
||||
|
migrationBuilder.AddForeignKey( |
||||
|
name: "FK_Orders_OrderStatus_OrderStatusId", |
||||
|
table: "Orders", |
||||
|
column: "OrderStatusId", |
||||
|
principalTable: "OrderStatus", |
||||
|
principalColumn: "Id", |
||||
|
onDelete: ReferentialAction.Cascade); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue