From dddb5c699a623de9a27615dd0ad65eb5b25a69cf Mon Sep 17 00:00:00 2001 From: matst80 Date: Fri, 3 Jul 2026 23:11:25 +0200 Subject: [PATCH] same stuff? --- pkg/cart/MUTATIONS.md | 22 +++++++++---- pkg/cart/mutation_line_item_marking.go | 20 ------------ pkg/cart/mutation_markings.go | 32 +++++++++++++++++++ pkg/cart/mutation_remove_line_item_marking.go | 18 ----------- 4 files changed, 47 insertions(+), 45 deletions(-) delete mode 100644 pkg/cart/mutation_line_item_marking.go create mode 100644 pkg/cart/mutation_markings.go delete mode 100644 pkg/cart/mutation_remove_line_item_marking.go diff --git a/pkg/cart/MUTATIONS.md b/pkg/cart/MUTATIONS.md index fb4299a..5cb8226 100644 --- a/pkg/cart/MUTATIONS.md +++ b/pkg/cart/MUTATIONS.md @@ -19,16 +19,15 @@ two-file version, the grouping is real. | `mutation_set_recovery_contact.go` (+ tests) | Recovery | — | `state.Recovery`, `state.UpdatedAt` | | `mutation_subscription_added.go` | Subscription | `state.Items` | `state.Subscriptions`, `state.UpdatedAt` | | `mutation_upsert_subscriptiondetails.go` | Subscription details | `state.Subscriptions` | `state.Subscriptions`, `state.UpdatedAt` | -| `mutation_remove_line_item_marking.go` | Markings | `state.Items[idx].Markings` | `state.Items[idx].Markings`, `state.UpdatedAt` | -| `mutation_line_item_marking.go` | Markings apply | `state.Items[idx].Markings` | `state.Items[idx].Markings`, `state.UpdatedAt` | +| `mutation_markings.go` (`mutation_line_item_marking.go` and `mutation_remove_line_item_marking.go` merged) | Markings apply/remove | `state.Items[idx].Markings` | `state.Items[idx].Markings`, `state.UpdatedAt` | ## Delete-test quick check -For any proposed grouping (e.g. merge all `marking*` mutations into one -file), ask: does deleting the merged file concentrate complexity, or just -move lines? For markings — yes, the shared logic (cascade to pricing) makes -the merge worthwhile. For `voucher` vs `custom_fields` — no, those read -different state and have different error contracts; keep separate. +For any proposed grouping, ask: does deleting the merged file concentrate +complexity, or just move lines? For markings — yes, the shared logic +(cascade to pricing) makes the merge worthwhile, and the merge is now done +(see below). For `voucher` vs `custom_fields` — no, those read different +state and have different error contracts; keep separate. ### What is already merged @@ -60,6 +59,15 @@ If a future merge lands, follow the same pattern: read the actual source to verify the row's claimed state surface, and prune label-noise before compressing two rows into one. +`pkg/cart/mutation_markings.go` (added 2025-07) — LineItemMarking and +RemoveLineItemMarking both touch `state.Items[idx].Markings` and share +the same item-lookup loop (find by ID, mutate `Marking` field). Merge +passed the delete-test: the shared write surface and identical error +contract ("item with ID %d not found") make the grouping real. No test +files existed for either mutation, so the test surface is unchanged. +Verified: `go build ./pkg/cart/...` and `go test -count=1 ./pkg/cart/...` +clean. + ### NOT to merge next `mutation_change_quantity.go` looks like an obvious candidate for the next diff --git a/pkg/cart/mutation_line_item_marking.go b/pkg/cart/mutation_line_item_marking.go deleted file mode 100644 index 03831cc..0000000 --- a/pkg/cart/mutation_line_item_marking.go +++ /dev/null @@ -1,20 +0,0 @@ -package cart - -import ( - "fmt" - - messages "git.k6n.net/mats/go-cart-actor/proto/cart" -) - -func LineItemMarking(grain *CartGrain, req *messages.LineItemMarking) error { - for i, item := range grain.Items { - if item.Id == req.Id { - grain.Items[i].Marking = &Marking{ - Type: req.Type, - Text: req.Marking, - } - return nil - } - } - return fmt.Errorf("item with ID %d not found", req.Id) -} diff --git a/pkg/cart/mutation_markings.go b/pkg/cart/mutation_markings.go new file mode 100644 index 0000000..0b19309 --- /dev/null +++ b/pkg/cart/mutation_markings.go @@ -0,0 +1,32 @@ +package cart + +import ( + "fmt" + + messages "git.k6n.net/mats/go-cart-actor/proto/cart" +) + +// LineItemMarking sets a marking on the line item with the given ID. +func LineItemMarking(grain *CartGrain, req *messages.LineItemMarking) error { + for i, item := range grain.Items { + if item.Id == req.Id { + grain.Items[i].Marking = &Marking{ + Type: req.Type, + Text: req.Marking, + } + return nil + } + } + return fmt.Errorf("item with ID %d not found", req.Id) +} + +// RemoveLineItemMarking clears the marking on the line item with the given ID. +func RemoveLineItemMarking(grain *CartGrain, req *messages.RemoveLineItemMarking) error { + for i, item := range grain.Items { + if item.Id == req.Id { + grain.Items[i].Marking = nil + return nil + } + } + return fmt.Errorf("item with ID %d not found", req.Id) +} diff --git a/pkg/cart/mutation_remove_line_item_marking.go b/pkg/cart/mutation_remove_line_item_marking.go deleted file mode 100644 index 68250bc..0000000 --- a/pkg/cart/mutation_remove_line_item_marking.go +++ /dev/null @@ -1,18 +0,0 @@ -package cart - -import ( - "fmt" - - messages "git.k6n.net/mats/go-cart-actor/proto/cart" -) - -func RemoveLineItemMarking(grain *CartGrain, req *messages.RemoveLineItemMarking) error { - - for i, item := range grain.Items { - if item.Id == req.Id { - grain.Items[i].Marking = nil - return nil - } - } - return fmt.Errorf("item with ID %d not found", req.Id) -}