add giftcards
This commit is contained in:
18
pkg/cart/mutation_remove_giftcard.go
Normal file
18
pkg/cart/mutation_remove_giftcard.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user