refactor/checkout (#8)
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 59s
Build and Publish / BuildAndDeployArm64 (push) Successful in 5m40s

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>
This commit was merged in pull request #8.
This commit is contained in:
2025-12-03 09:45:48 +01:00
committed by mats
parent ebd1508294
commit ee5f54f0dd
77 changed files with 5190 additions and 5795 deletions

View File

@@ -0,0 +1,55 @@
package checkout
import (
"fmt"
"git.k6n.net/go-cart-actor/pkg/cart"
messages "git.k6n.net/go-cart-actor/proto/checkout"
)
func asPickupPoint(p *messages.PickupPoint, deliveryId uint32) *PickupPoint {
if p == nil {
return nil
}
return &PickupPoint{
Id: p.Id,
Name: p.Name,
Address: p.Address,
City: p.City,
Country: p.Country,
Zip: p.Zip,
}
}
// HandleSetDelivery mutation
// HandleSetDelivery mutation
func HandleSetDelivery(g *CheckoutGrain, m *messages.SetDelivery) error {
if m == nil {
return fmt.Errorf("HandleSetDelivery: nil payload")
}
if m.Provider == "" {
return fmt.Errorf("HandleSetDelivery: missing provider")
}
// Check if delivery already exists, update or add
for _, d := range g.Deliveries {
if d.Provider == m.Provider {
// Update existing
d.Items = m.Items
d.PickupPoint = asPickupPoint(m.PickupPoint, d.Id)
return nil
}
}
// Add new delivery
g.lastDeliveryId++
delivery := &CheckoutDelivery{
Id: g.lastDeliveryId,
Provider: m.Provider,
Items: m.Items,
PickupPoint: asPickupPoint(m.PickupPoint, g.lastDeliveryId),
Price: *cart.NewPrice(), // Price might need calculation, but for now zero
}
g.Deliveries = append(g.Deliveries, delivery)
return nil
}