Skip to content

Commit d3d88de

Browse files
committed
Update order saga cancel and ship commands
1 parent 90daff2 commit d3d88de

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
using Ordering.API.Application.IntegrationCommands.Commands;
99
using Ordering.API.Application.IntegrationEvents;
1010
using Ordering.Domain.Exceptions;
11-
using System;
12-
using System.Linq;
1311
using System.Threading.Tasks;
14-
using Ordering.API.Application.IntegrationEvents;
1512

1613
namespace Ordering.API.Application.Sagas
1714
{
@@ -28,14 +25,11 @@ public class OrderProcessSaga : OrderSaga,
2825
IAsyncRequestHandler<CancelOrderCommand, bool>,
2926
IAsyncRequestHandler<ShipOrderCommand, bool>
3027
{
31-
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
3228

3329
public OrderProcessSaga(
34-
OrderingContext orderingContext,
35-
IOrderingIntegrationEventService orderingIntegrationEventService)
30+
OrderingContext orderingContext)
3631
: base(orderingContext)
3732
{
38-
_orderingIntegrationEventService = orderingIntegrationEventService;
3933
}
4034

4135
/// <summary>
@@ -79,7 +73,7 @@ public async Task<bool> Handle(CancelOrderCommand command)
7973
if (orderSaga.GetOrderStatusId() != OrderStatus.Cancelled.Id
8074
|| orderSaga.GetOrderStatusId() != OrderStatus.Shipped.Id)
8175
{
82-
orderSaga.SetOrderStatusId(OrderStatus.Cancelled.Id);
76+
orderSaga.SetCancelStatus();
8377
result = await SaveChangesAsync();
8478
}
8579
return result;
@@ -101,7 +95,7 @@ public async Task<bool> Handle(ShipOrderCommand command)
10195
// its status is paid
10296
if (orderSaga.GetOrderStatusId() == OrderStatus.Paid.Id)
10397
{
104-
orderSaga.SetOrderStatusId(OrderStatus.Shipped.Id);
98+
orderSaga.SetShippedStatus();
10599
result = await SaveChangesAsync();
106100
}
107101
return result;

src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ public void SetShippedStatus()
166166
//Call Domain Event
167167
}
168168

169+
public void SetCancelStatus()
170+
{
171+
if (_orderStatusId == OrderStatus.Shipped.Id)
172+
{
173+
throw new OrderingDomainException("Not possible to change order status. Reason: cannot cancel order it is already shipped");
174+
}
175+
_orderStatusId = OrderStatus.Cancelled.Id;
176+
}
177+
169178
#endregion
170179

171180
public int GetOrderStatusId()

0 commit comments

Comments
 (0)