split cart and checkout and checkout vs payments
This commit is contained in:
49
pkg/checkout/mutation_order_created.go
Normal file
49
pkg/checkout/mutation_order_created.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package checkout
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
messages "git.k6n.net/go-cart-actor/proto/checkout"
|
||||
)
|
||||
|
||||
// mutation_order_created.go
|
||||
//
|
||||
// Registers the OrderCreated mutation.
|
||||
//
|
||||
// This mutation represents the completion (or state transition) of an order
|
||||
// initiated earlier via InitializeCheckout / external processing.
|
||||
// It finalizes (or updates) the checkout's order metadata.
|
||||
//
|
||||
// Behavior:
|
||||
// - Validates payload non-nil and OrderId not empty.
|
||||
// - Sets Status from payload.Status.
|
||||
// - Sets OrderId if not already set.
|
||||
// - Does NOT adjust monetary totals.
|
||||
//
|
||||
// Notes / Future Extensions:
|
||||
// - If multiple order completion events can arrive (e.g., retries / webhook
|
||||
// replays), this handler is idempotent: it simply overwrites fields.
|
||||
// - If you need to guard against conflicting order IDs, add a check:
|
||||
// if g.OrderId != "" && g.OrderId != m.OrderId { ... }
|
||||
// - Add audit logging or metrics here if required.
|
||||
//
|
||||
// Concurrency:
|
||||
// - Relies on the higher-level guarantee that Apply() calls are serialized
|
||||
// per grain. If out-of-order events are possible, embed versioning or
|
||||
// timestamps in the mutation and compare before applying changes.
|
||||
|
||||
func HandleOrderCreated(g *CheckoutGrain, m *messages.OrderCreated) error {
|
||||
if m == nil {
|
||||
return fmt.Errorf("HandleOrderCreated: nil payload")
|
||||
}
|
||||
if m.OrderId == "" {
|
||||
return fmt.Errorf("OrderCreated: missing orderId")
|
||||
}
|
||||
if g.OrderId == nil {
|
||||
g.OrderId = &m.OrderId
|
||||
} else if *g.OrderId != m.OrderId {
|
||||
return fmt.Errorf("OrderCreated: conflicting order ID")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user