mutation fixes
This commit is contained in:
@@ -73,6 +73,33 @@ func (c *CartMutationContext) ReleaseItem(ctx context.Context, cartId CartId, sk
|
||||
return c.reservationService.Release(ctx, inventory.SKU(sku), l, inventory.CartID(cartId.String()))
|
||||
}
|
||||
|
||||
// equalOptional is the canonical nullable-equality primitive used by the
|
||||
// cart mutations when deciding whether two identifier fields (parent/child
|
||||
// links, store ids, anything else nullable) refer to the same thing.
|
||||
//
|
||||
// Returns true when both pointers are nil, when both alias the same
|
||||
// address, or when both are non-nil and dereference to equal values. The
|
||||
// same-address short-circuit is a no-op for correctness but lets a caller
|
||||
// who passes the same variable get back true without traversing the
|
||||
// generic's comparison path.
|
||||
//
|
||||
// One tested primitive covers every *T the cart currently compares —
|
||||
// `*uint32` for ParentId, `*string` for StoreId — and any future
|
||||
// comparable pointer type. Hand-rolled "both nil OR both non-nil and
|
||||
// equal" expressions were duplicated at AddItem's merge site and were a
|
||||
// footgun whenever a new field was added (which axis of the predicate
|
||||
// was the relevant one?). Keeping a single helper makes future merges
|
||||
// safer to copy.
|
||||
func equalOptional[T comparable](a, b *T) bool {
|
||||
if a == b { // both nil OR same address
|
||||
return true
|
||||
}
|
||||
if a == nil || b == nil {
|
||||
return false
|
||||
}
|
||||
return *a == *b
|
||||
}
|
||||
|
||||
// CascadeChildQuantities scales every direct child's quantity
|
||||
// proportionally when a parent's quantity is bumped (ChangeQuantity or
|
||||
// the AddItem-merge path).
|
||||
|
||||
Reference in New Issue
Block a user