diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs index cf232c60..4d3c7806 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/IOrderAppService.cs @@ -8,4 +8,5 @@ public interface IOrderAppService : IApplicationService { Task CreateAsync(OrderCreateDto input); Task GetAsync(Guid id); + Task GetByOrderNoAsync(int orderNo); } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs index bdb3fd17..a65219b7 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs @@ -29,6 +29,11 @@ public class OrderAppService : ApplicationService, IOrderAppService return await CreateOrderDtoMappingAsync(order); } + public Task GetByOrderNoAsync(int orderNo) + { + var order = await _orderRepository.get + } + public async Task CreateAsync(OrderCreateDto input) { var orderItems = GetProductListTuple(input.Products); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs index 65c20d35..b875886c 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/IOrderRepository.cs +++ b/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 { + Task GetByOrderNoAsync(int orderNo, + bool includeDetails = true, + CancellationToken cancellationToken = default); } \ 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 index 28e56344..8001fc8e 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -11,7 +11,7 @@ public class Order : AggregateRoot 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 { } - 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; diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220107102140_Added-OrderNo.Designer.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220107102140_Added-OrderNo.Designer.cs new file mode 100644 index 00000000..59c1f223 --- /dev/null +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220107102140_Added-OrderNo.Designer.cs @@ -0,0 +1,233 @@ +// +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("Id") + .HasColumnType("integer") + .HasDefaultValue(1); + + b.Property("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("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("PaymentRequestId") + .HasColumnType("uuid"); + + b.Property("PaymentStatus") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("_orderStatusId") + .HasColumnType("integer") + .HasColumnName("OrderStatusId"); + + b.Property("_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("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.HasOne("EShopOnAbp.OrderingService.Buyers.PaymentType", "PaymentType") + .WithMany() + .HasForeignKey("_paymentTypeId") + .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"); + + 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 + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220107102140_Added-OrderNo.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/20220107102140_Added-OrderNo.cs new file mode 100644 index 00000000..8a5d3297 --- /dev/null +++ b/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( + name: "OrderNo", + table: "Orders", + type: "integer", + nullable: false, + defaultValue: 0); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "OrderNo", + table: "Orders"); + } + } +} diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs index 79591235..550b95bc 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Migrations/OrderingServiceDbContextModelSnapshot.cs @@ -58,6 +58,9 @@ namespace EShopOnAbp.OrderingService.Migrations b.Property("OrderDate") .HasColumnType("timestamp with time zone"); + b.Property("OrderNo") + .HasColumnType("integer"); + b.Property("PaymentRequestId") .HasColumnType("uuid"); diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderQueryableExtensions.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderQueryableExtensions.cs new file mode 100644 index 00000000..da4c615d --- /dev/null +++ b/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 IncludeDetails(this IQueryable 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); + } +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs index 8d13116d..b1e95940 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs @@ -25,10 +25,19 @@ public class EfCoreOrderRepository : EfCoreRepository 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> WithDetailsAsync() { return (await GetQueryableAsync()) - .Include(q => q.OrderStatus) - .Include(q => q.PaymentType); + .IncludeDetails(); } } \ No newline at end of file