-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
order create saga pattern implementation
- Loading branch information
Oğuzhan Aydın
committed
Apr 28, 2021
1 parent
b853c48
commit f9c0d93
Showing
7 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...ication/IntegrationEvents/EventHandlers/RemoveProductStockErrorIntegrationEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Order.Api.Application.IntegrationEvents.Events; | ||
using Order.Api.Domain; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Zero.Core.Repositories; | ||
using Zero.Core.UnitOfWork; | ||
using Zero.EventBus.Abstractions; | ||
|
||
namespace Order.Api.Application.IntegrationEvents.EventHandlers | ||
{ | ||
public class RemoveProductStockErrorIntegrationEventHandler : IIntegrationEventHandler<RemoveProductStockErrorIntegrationEvent> | ||
{ | ||
#region .ctor | ||
|
||
private readonly IRepository<Domain.Order> _orderRepository; | ||
private readonly IRepository<OrderItem> _orderItemRepository; | ||
private readonly ILogger<RemoveProductStockErrorIntegrationEventHandler> _logger; | ||
private readonly IUnitOfWork _uow; | ||
|
||
public RemoveProductStockErrorIntegrationEventHandler(IRepository<Domain.Order> orderRepository, IRepository<OrderItem> orderItemRepository, ILogger<RemoveProductStockErrorIntegrationEventHandler> logger, IUnitOfWork uow) | ||
{ | ||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); | ||
_orderItemRepository = orderItemRepository ?? throw new ArgumentNullException(nameof(orderItemRepository)); | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
_uow = uow ?? throw new ArgumentNullException(nameof(uow)); | ||
} | ||
|
||
#endregion | ||
|
||
public async Task Handle(RemoveProductStockErrorIntegrationEvent @event) | ||
{ | ||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | ||
|
||
await _orderItemRepository.DeleteAsync(x => x.Order.Id == @event.OrderId); | ||
await _orderRepository.DeleteAsync(x => x.Id == @event.OrderId); | ||
await _uow.SaveAsync(); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...Order.Api/Application/IntegrationEvents/Events/RemoveProductStockErrorIntegrationEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Zero.EventBus.Events; | ||
|
||
namespace Order.Api.Application.IntegrationEvents.Events | ||
{ | ||
public record RemoveProductStockErrorIntegrationEvent : IntegrationEvent | ||
{ | ||
public int OrderId { get; } | ||
|
||
public RemoveProductStockErrorIntegrationEvent(int orderId) | ||
{ | ||
OrderId = orderId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...oduct.Api/Application/IntegrationEvents/Events/RemoveProductStockErrorIntegrationEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Zero.EventBus.Events; | ||
|
||
namespace Product.Api.Application.IntegrationEvents.Events | ||
{ | ||
public record RemoveProductStockErrorIntegrationEvent : IntegrationEvent | ||
{ | ||
public int OrderId { get; } | ||
|
||
public RemoveProductStockErrorIntegrationEvent(int orderId) | ||
{ | ||
OrderId = orderId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters