add giftcards

This commit is contained in:
matst80
2025-11-21 10:14:33 +01:00
parent 896bf7672b
commit 886e3ce48f
7 changed files with 374 additions and 16 deletions

View File

@@ -0,0 +1,18 @@
package cart
import (
"fmt"
messages "git.tornberg.me/go-cart-actor/pkg/messages"
)
func RemoveGiftcard(grain *CartGrain, req *messages.RemoveGiftcard) error {
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)
}