Files
go-cart-actor/pkg/cart/mutation_remove_giftcard.go
matst80 060b3dfbf0
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 36s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m59s
more changes
2025-12-01 20:15:48 +01:00

22 lines
475 B
Go

package cart
import (
"fmt"
messages "git.k6n.net/go-cart-actor/pkg/messages"
)
func RemoveGiftcard(grain *CartGrain, req *messages.RemoveGiftcard) error {
if grain.PaymentInProgress > 0 {
return ErrPaymentInProgress
}
for i, item := range grain.Giftcards {
if item.Id == req.Id {
grain.Giftcards = append(grain.Giftcards[:i], grain.Giftcards[i+1:]...)
grain.UpdateTotals()
return nil
}
}
return fmt.Errorf("giftcard with ID %d not found", req.Id)
}