Co-authored-by: matst80 <mats.tornberg@gmail.com> Reviewed-on: #8 Co-authored-by: Mats Törnberg <mats@tornberg.me> Co-committed-by: Mats Törnberg <mats@tornberg.me>
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package checkout
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
messages "git.k6n.net/go-cart-actor/proto/checkout"
|
|
)
|
|
|
|
// mutation_set_pickup_point.go
|
|
//
|
|
// Registers the SetPickupPoint mutation using the generic mutation registry.
|
|
//
|
|
// Semantics (mirrors original switch-based implementation):
|
|
// - Locate the delivery with Id == payload.DeliveryId
|
|
// - Set (or overwrite) its PickupPoint with the provided data
|
|
// - Does NOT alter pricing or taxes (so no totals recalculation required)
|
|
//
|
|
// Validation / Error Handling:
|
|
// - If payload is nil -> error
|
|
// - If DeliveryId not found -> error
|
|
//
|
|
// Concurrency:
|
|
// - Relies on the existing expectation that higher-level mutation routing
|
|
// serializes Apply() calls per grain; if stricter guarantees are needed,
|
|
// a delivery-level lock could be introduced later.
|
|
//
|
|
// Future Extensions:
|
|
// - Validate pickup point fields (country code, zip format, etc.)
|
|
// - Track history / audit of pickup point changes
|
|
// - Trigger delivery price adjustments (which would then require WithTotals()).
|
|
|
|
func HandleSetPickupPoint(g *CheckoutGrain, m *messages.SetPickupPoint) error {
|
|
if m == nil {
|
|
return fmt.Errorf("SetPickupPoint: nil payload")
|
|
}
|
|
|
|
for _, d := range g.Deliveries {
|
|
if d.Id == uint32(m.DeliveryId) {
|
|
d.PickupPoint = &PickupPoint{
|
|
Id: m.PickupPoint.Id,
|
|
Name: m.PickupPoint.Name,
|
|
Address: m.PickupPoint.Address,
|
|
City: m.PickupPoint.City,
|
|
Zip: m.PickupPoint.Zip,
|
|
Country: m.PickupPoint.Country,
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
return fmt.Errorf("SetPickupPoint: delivery id %d not found", m.DeliveryId)
|
|
}
|