Browse Source

Added cancel processes

It will been continued enhancement.
pull/92/head
malik masis 5 years ago
parent
commit
c6ad45023d
  1. 6
      services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/UpdateOrderDto.cs
  2. 13
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs
  3. 16
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderCancelledEto.cs
  4. 13
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs
  5. 24
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs
  6. 4
      services/ordering/test/EShopOnAbp.OrderingService.Application.Tests/Orders/OrderApplication_Tests.cs
  7. 4
      services/payment/src/EShopOnAbp.PaymentService.Domain/EShopOnAbp.PaymentService.Domain.csproj
  8. 26
      services/payment/src/EShopOnAbp.PaymentService.Domain/EventHandlers/OrderCancelledEventHandler.cs

6
services/ordering/src/EShopOnAbp.OrderingService.Application.Contracts/Orders/UpdateOrderDto.cs

@ -1,7 +1,11 @@
namespace EShopOnAbp.OrderingService.Orders
using System;
namespace EShopOnAbp.OrderingService.Orders
{
public class UpdateOrderDto
{
public int OrderStatusId { get; set; }
public Guid PaymentRequestId { get; set; }
public string PaymentRequestStatus { get; set; }
}
}

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

@ -55,10 +55,17 @@ public class OrderAppService : ApplicationService, IOrderAppService
public async Task<OrderDto> UpdateAsync(Guid id, UpdateOrderDto input)
{
var order = await _orderRepository.GetAsync(id);
order.SetOrder(input.OrderStatusId);
await _orderRepository.UpdateAsync(order);
return CreateOrderDtoMapping(order);
if (input.OrderStatusId == OrderStatus.Shipped.Id)
{
order.SetOrderAsShipped(input.OrderStatusId);
await _orderRepository.UpdateAsync(order);
}
else if (input.OrderStatusId == OrderStatus.Cancelled.Id)
{
await _orderManager.CancelOrderAsync(id, input.PaymentRequestId, input.PaymentRequestStatus);
}
return CreateOrderDtoMapping(order);
}
public async Task<OrderDto> CreateAsync(OrderCreateDto input)

16
services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderCancelledEto.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus;
namespace EShopOnAbp.OrderingService.Orders;
[EventName("EShopOnAbp.Order.Cancelled")]
public class OrderCancelledEto : EtoBase
{
public Guid OrderId { get; set; }
public int OrderNo { get; set; }
public DateTime OrderDate { get; set; }
public BuyerEto Buyer { get; set; }
public List<OrderItemEto> Items { get; set; } = new();
}

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

@ -59,6 +59,15 @@ public class Order : AggregateRoot<Guid>
return this;
}
public Order SetOrderCancelled(Guid paymentRequestId, string paymentRequestStatus)
{
PaymentRequestId = paymentRequestId;
PaymentStatus = paymentRequestStatus;
OrderStatus = OrderStatus.Cancelled;
return this;
}
public Order AddOrderItem(Guid id, Guid productId, string productName, string productCode, decimal unitPrice,
decimal discount, string pictureUrl, int units = 1)
{
@ -88,14 +97,14 @@ public class Order : AggregateRoot<Guid>
return OrderItems.Sum(o => o.Units * o.UnitPrice);
}
public Order SetOrder(int orderStatus)
public Order SetOrderAsShipped(int orderStatus)
{
if (orderStatus == OrderStatus.Cancelled.Id)
{
return this;
}
//TODO no enough to update the object.
_orderStatusId = orderStatus;
_orderStatusId = OrderStatus.Shipped.Id;
return this;
}
}

24
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs

@ -91,6 +91,30 @@ public class OrderManager : DomainService
return await _orderRepository.UpdateAsync(order, autoSave: true);
}
public async Task<Order> CancelOrderAsync(Guid orderId, Guid paymentRequestId, string paymentRequestStatus)
{
var order = await _orderRepository.GetAsync(orderId);
if (order == null)
{
throw new BusinessException(OrderingServiceErrorCodes.OrderWithIdNotFound)
.WithData("OrderId", orderId);
}
order.SetOrderCancelled(paymentRequestId, paymentRequestStatus);
// Publish order cancelled event
await _distributedEventBus.PublishAsync(new OrderCancelledEto
{
OrderId = order.Id,
OrderDate = order.OrderDate,
OrderNo = order.OrderNo,
Buyer = GetBuyerEto(order.Buyer),
Items = GetProductItemEtoList(order.OrderItems)
});
return await _orderRepository.UpdateAsync(order, autoSave: true);
}
private BuyerEto GetBuyerEto(Buyer buyer)
{
return new BuyerEto

4
services/ordering/test/EShopOnAbp.OrderingService.Application.Tests/Orders/OrderApplication_Tests.cs

@ -69,9 +69,9 @@ public class OrderApplication_Tests : OrderingServiceApplicationTestBase
var cancelledMyOrder = await _orderAppService.UpdateAsync(placedOrder.Id, new UpdateOrderDto()
{
OrderStatusId = OrderStatus.Cancelled.Id,
OrderStatusId = OrderStatus.Shipped.Id,
});
//TODO - temp value - it should be Cancelled
//TODO - temp value - it should be Shipped
cancelledMyOrder.OrderStatus.ShouldBe(OrderStatus.Placed.ToString());

4
services/payment/src/EShopOnAbp.PaymentService.Domain/EShopOnAbp.PaymentService.Domain.csproj

@ -12,4 +12,8 @@
<ProjectReference Include="..\EShopOnAbp.PaymentService.Domain.Shared\EShopOnAbp.PaymentService.Domain.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\ordering\src\EShopOnAbp.OrderingService.Domain.Shared\EShopOnAbp.OrderingService.Domain.Shared.csproj" />
</ItemGroup>
</Project>

26
services/payment/src/EShopOnAbp.PaymentService.Domain/EventHandlers/OrderCancelledEventHandler.cs

@ -0,0 +1,26 @@
using EShopOnAbp.OrderingService.Orders;
using EShopOnAbp.PaymentService.PaymentRequests;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Uow;
namespace EShopOnAbp.PaymentService.EventHandlers
{
public class OrderCancelledEventHandler : IDistributedEventHandler<OrderCancelledEto>, ITransientDependency
{
private readonly IPaymentRequestRepository _paymentRepository;
public OrderCancelledEventHandler(IPaymentRequestRepository paymenRepository)
{
_paymentRepository = paymenRepository;
}
[UnitOfWork]
public async Task HandleEventAsync(OrderCancelledEto eventData)
{
var payment = await _paymentRepository.GetAsync(eventData.Buyer.BuyerId.GetValueOrDefault());
await _paymentRepository.DeleteAsync(payment);
}
}
}
Loading…
Cancel
Save