19 lines
408 B
Go
19 lines
408 B
Go
package cart
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
messages "git.k6n.net/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)
|
|
}
|