Files
go-cart-actor/pkg/cart/mutation_set_custom_fields.go
T
mats 60722e3414
Build and Publish / BuildAndDeployArm64 (push) Failing after 49s
Build and Publish / BuildAndDeployAmd64 (push) Has been cancelled
fixes
2026-06-16 13:14:35 +02:00

32 lines
884 B
Go

package cart
import (
"fmt"
messages "git.k6n.net/go-cart-actor/proto/cart"
)
// SetLineItemCustomFields sets/merges user-supplied custom input fields on an
// existing cart line. It is the dict equivalent of LineItemMarking: keys in the
// request are upserted; existing keys not present in the request are left
// untouched. (Send an empty value to clear a single field at the API layer if
// desired.)
func SetLineItemCustomFields(grain *CartGrain, req *messages.SetLineItemCustomFields) error {
for _, item := range grain.Items {
if item.Id != req.Id {
continue
}
if len(req.CustomFields) == 0 {
return nil
}
if item.CustomFields == nil {
item.CustomFields = make(map[string]string, len(req.CustomFields))
}
for k, v := range req.CustomFields {
item.CustomFields[k] = v
}
return nil
}
return fmt.Errorf("item with ID %d not found", req.Id)
}