File tree Expand file tree Collapse file tree
src/MicroCommerce.ApiService/Features/Ordering Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using MassTransit ;
22using MediatR ;
3+ using MicroCommerce . ApiService . Features . Ordering . Application . Saga ;
34using MicroCommerce . ApiService . Features . Ordering . Domain . ValueObjects ;
45using MicroCommerce . ApiService . Features . Ordering . Infrastructure ;
56using Microsoft . EntityFrameworkCore ;
Original file line number Diff line number Diff line change 1+ using MassTransit ;
2+ using MicroCommerce . ApiService . Features . Ordering . Application . Saga ;
3+ using MicroCommerce . ApiService . Features . Ordering . Domain . Events ;
4+ using MicroCommerce . ApiService . Features . Ordering . Domain . ValueObjects ;
5+ using MicroCommerce . ApiService . Features . Ordering . Infrastructure ;
6+ using Microsoft . EntityFrameworkCore ;
7+
8+ namespace MicroCommerce . ApiService . Features . Ordering . Application . Consumers ;
9+
10+ /// <summary>
11+ /// Bridges the domain event (OrderSubmittedDomainEvent) to the checkout saga (CheckoutStarted).
12+ /// Domain events are thin (ID-only); this consumer loads order data and publishes the saga-initiating event.
13+ /// </summary>
14+ public sealed class OrderSubmittedConsumer ( OrderingDbContext context )
15+ : IConsumer < OrderSubmittedDomainEvent >
16+ {
17+ public async Task Consume ( ConsumeContext < OrderSubmittedDomainEvent > context1 )
18+ {
19+ OrderId orderId = OrderId . From ( context1 . Message . OrderId ) ;
20+
21+ Domain . Entities . Order ? order = await context . Orders
22+ . Include ( o => o . Items )
23+ . FirstOrDefaultAsync ( o => o . Id == orderId ) ;
24+
25+ if ( order is null )
26+ {
27+ return ;
28+ }
29+
30+ List < CheckoutItem > items = order . Items
31+ . Select ( i => new CheckoutItem { ProductId = i . ProductId , Quantity = i . Quantity } )
32+ . ToList ( ) ;
33+
34+ await context1 . Publish ( new CheckoutStarted
35+ {
36+ OrderId = order . Id . Value ,
37+ BuyerId = order . BuyerId ,
38+ BuyerEmail = order . BuyerEmail ,
39+ Items = items
40+ } ) ;
41+ }
42+ }
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments