27 lines
462 B
Go
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
|
|
}
|