Browse Source

Added OrderNo

pull/58/head
Galip Tolga Erdem 5 years ago
parent
commit
bf53621cd6
  1. 1
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs
  2. 5
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs
  3. 5
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs
  4. 5
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs
  5. 233
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220107102140_Added-OrderNo.Designer.cs
  6. 26
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220107102140_Added-OrderNo.cs
  7. 3
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs
  8. 18
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderQueryableExtensions.cs
  9. 13
      services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs

1
services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs

@ -8,4 +8,5 @@ public interface IOrderAppService : IApplicationService
{
Task<OrderDto> CreateAsync(OrderCreateDto input);
Task<OrderDto> GetAsync(Guid id);
Task<OrderDto> GetByOrderNoAsync(int orderNo);
}

5
services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs

@ -29,6 +29,11 @@ public class OrderAppService : ApplicationService, IOrderAppService
return await CreateOrderDtoMappingAsync(order);
}
public Task<OrderDto> GetByOrderNoAsync(int orderNo)
{
var order = await _orderRepository.get
}
public async Task<OrderDto> CreateAsync(OrderCreateDto input)
{
var orderItems = GetProductListTuple(input.Products);

5
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs

@ -1,8 +1,13 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace EShopOnAbp.OrderingService.Orders;
public interface IOrderRepository : IRepository<Order, Guid>
{
Task<Order> GetByOrderNoAsync(int orderNo,
bool includeDetails = true,
CancellationToken cancellationToken = default);
}

5
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs

@ -11,7 +11,7 @@ public class Order : AggregateRoot<Guid>
private int _orderStatusId;
private int _paymentTypeId;
public DateTime OrderDate { get; private set; }
public int OrderNo { get; private set; }
public PaymentType PaymentType { get; private set; }
public Guid? PaymentRequestId { get; private set; }
public string PaymentStatus { get; private set; }
@ -24,11 +24,12 @@ public class Order : AggregateRoot<Guid>
{
}
internal Order(Guid id, Buyer buyer, Address address,PaymentType paymentType, 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;
OrderNo = id.GetHashCode();
Buyer = buyer;
Address = address;
PaymentRequestId = paymentRequestId;

233
services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220107102140_Added-OrderNo.Designer.cs

@ -0,0 +1,233 @@
// <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("20220107102140_Added-OrderNo")]
partial class AddedOrderNo
{
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<int>("Id")
.HasColumnType("integer")
.HasDefaultValue(1);
b.Property<string>("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<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 with time zone");
b.Property<int>("OrderNo")
.HasColumnType("integer");
b.Property<Guid?>("PaymentRequestId")
.HasColumnType("uuid");
b.Property<string>("PaymentStatus")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<int>("_orderStatusId")
.HasColumnType("integer")
.HasColumnName("OrderStatusId");
b.Property<int>("_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<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.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.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<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");
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
}
}
}

26
services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220107102140_Added-OrderNo.cs

@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EShopOnAbp.OrderingService.Migrations
{
public partial class AddedOrderNo : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "OrderNo",
table: "Orders",
type: "integer",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "OrderNo",
table: "Orders");
}
}
}

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

@ -58,6 +58,9 @@ namespace EShopOnAbp.OrderingService.Migrations
b.Property<DateTime>("OrderDate")
.HasColumnType("timestamp with time zone");
b.Property<int>("OrderNo")
.HasColumnType("integer");
b.Property<Guid?>("PaymentRequestId")
.HasColumnType("uuid");

18
services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderQueryableExtensions.cs

@ -0,0 +1,18 @@
using System.Linq;
using EShopOnAbp.OrderingService.Orders;
using Microsoft.EntityFrameworkCore;
public static class EfCoreOrderQueryableExtensions
{
public static IQueryable<Order> IncludeDetails(this IQueryable<Order> queryable, bool include = true)
{
return !include
? queryable
: queryable
.Include(q => q.OrderStatus)
.Include(q => q.PaymentType)
.Include(q => q.Address)
.Include(q => q.Buyer)
.Include(q => q.OrderItems);
}
}

13
services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs

@ -25,10 +25,19 @@ public class EfCoreOrderRepository : EfCoreRepository<OrderingServiceDbContext,
return newEntity;
}
public async Task<Order> GetByOrderNoAsync(
int orderNo,
bool includeDetails = true,
CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync())
.IncludeDetails(includeDetails)
.FirstOrDefaultAsync(q => q.OrderNo == orderNo, cancellationToken: GetCancellationToken(cancellationToken));
}
public override async Task<IQueryable<Order>> WithDetailsAsync()
{
return (await GetQueryableAsync())
.Include(q => q.OrderStatus)
.Include(q => q.PaymentType);
.IncludeDetails();
}
}
Loading…
Cancel
Save