refactor
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
// retries delivery on its own. With a nil publisher (dev without AMQP) it is a
|
||||
// no-op. Attach it to the "after" hooks of the final paid step, e.g. capture.
|
||||
func RegisterOrderCreatedEmit(reg *flow.Registry, app Applier, pub Publisher, exchange, source string) {
|
||||
reg.Hook("emit_order_created", func(ctx context.Context, st *flow.State, _ flow.HookInfo, _ json.RawMessage) error {
|
||||
reg.HookWithMeta("emit_order_created", func(ctx context.Context, st *flow.State, _ flow.HookInfo, _ json.RawMessage) error {
|
||||
if pub == nil {
|
||||
return nil // no broker configured (dev)
|
||||
}
|
||||
@@ -51,19 +51,21 @@ func RegisterOrderCreatedEmit(reg *flow.Registry, app Applier, pub Publisher, ex
|
||||
return err
|
||||
}
|
||||
return pub.Publish(exchange, string(event.OrderCreated), body)
|
||||
}, flow.CapabilityMeta{
|
||||
Description: "Emit the order.created domain event after a paid order is finalized.",
|
||||
})
|
||||
}
|
||||
|
||||
// buildOrderCreated projects the grain onto the exported order.created contract.
|
||||
// Lines carry only SKU + quantity (what reactors need); inventory commits at the
|
||||
// order's Country location.
|
||||
// Lines carry SKU, quantity, the inventory commit location, and the drop-ship
|
||||
// flag so the inventory reactor can skip the stock decrement for supplier-fulfilled items.
|
||||
func buildOrderCreated(o *OrderGrain) contract.Created {
|
||||
lines := make([]contract.Line, 0, len(o.Lines))
|
||||
for _, l := range o.Lines {
|
||||
if l.Sku == "" || l.Quantity <= 0 {
|
||||
continue
|
||||
}
|
||||
lines = append(lines, contract.Line{SKU: l.Sku, Quantity: l.Quantity, Location: l.Location})
|
||||
lines = append(lines, contract.Line{SKU: l.Sku, Quantity: l.Quantity, Location: l.Location, DropShip: l.DropShip})
|
||||
}
|
||||
return contract.Created{
|
||||
OrderID: OrderId(o.Id).String(),
|
||||
|
||||
Reference in New Issue
Block a user