Files
go-cart-actor/cmd/cart/mutation_add_voucher.go
matst80 6c44a03dd1
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
test add vouchers and shared service
2025-10-14 09:10:01 +02:00

27 lines
462 B
Go

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
}