test add vouchers and shared service
Some checks failed
Build and Publish / Metadata (push) Successful in 13s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m22s
Build and Publish / BuildAndDeployArm64 (push) Has been cancelled

This commit is contained in:
matst80
2025-10-14 09:10:01 +02:00
parent 11e82de114
commit 6c44a03dd1
7 changed files with 152 additions and 18 deletions

View File

@@ -0,0 +1,26 @@
package main
import (
"fmt"
"git.tornberg.me/go-cart-actor/pkg/messages"
)
func (ctx *MutationContext) AddVoucher(g *CartGrain, m *messages.AddVoucher) error {
if m == nil {
return fmt.Errorf("AddVoucher: nil payload")
}
voucher, err := ctx.VoucherService.GetVoucher(m.Code)
if err != nil {
return fmt.Errorf("AddVoucher: %w", err)
}
if voucher == nil {
return nil
}
g.Vouchers = append(g.Vouchers, voucher)
g.UpdateTotals()
return nil
}