test add vouchers and shared service
This commit is contained in:
26
cmd/cart/mutation_add_voucher.go
Normal file
26
cmd/cart/mutation_add_voucher.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user