change alot of id values
All checks were successful
Build and Publish / Metadata (push) Successful in 15s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m11s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m7s

This commit is contained in:
matst80
2025-10-14 21:24:50 +02:00
parent 4bec3f8cc0
commit 1565cfdaba
14 changed files with 426 additions and 332 deletions

View File

@@ -1,15 +1,13 @@
package main
import (
"fmt"
"slices"
"git.tornberg.me/go-cart-actor/pkg/actor"
"git.tornberg.me/go-cart-actor/pkg/messages"
"git.tornberg.me/go-cart-actor/pkg/voucher"
)
func (ctx *MutationContext) AddVoucher(g *CartGrain, m *messages.AddVoucher) error {
func AddVoucher(g *CartGrain, m *messages.AddVoucher) error {
if m == nil {
return &actor.MutationError{
Message: "AddVoucher: nil payload",
@@ -18,7 +16,7 @@ func (ctx *MutationContext) AddVoucher(g *CartGrain, m *messages.AddVoucher) err
}
}
if slices.ContainsFunc(g.Vouchers, func(v *voucher.Voucher) bool {
if slices.ContainsFunc(g.Vouchers, func(v *Voucher) bool {
return v.Code == m.Code
}) {
return &actor.MutationError{
@@ -28,20 +26,13 @@ func (ctx *MutationContext) AddVoucher(g *CartGrain, m *messages.AddVoucher) err
}
}
voucherData, err := ctx.VoucherService.GetVoucher(m.Code)
if err != nil {
return &actor.MutationError{
Message: fmt.Sprintf("cant find voucher: %v", err),
Code: 1003,
StatusCode: 400,
}
}
if voucherData == nil {
return nil
}
g.Vouchers = append(g.Vouchers, voucherData)
g.lastVoucherId++
g.Vouchers = append(g.Vouchers, &Voucher{
Id: g.lastVoucherId,
Code: m.Code,
Rules: m.VoucherRules,
Value: *NewPriceFromIncVat(m.Value, 25.0),
})
g.UpdateTotals()
return nil
}