safe truncation
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 27s
Build and Publish / BuildAndDeploy (push) Successful in 2m19s

This commit is contained in:
matst80
2024-11-12 20:51:39 +01:00
parent 983d1d52ae
commit 39244350e8
3 changed files with 26 additions and 11 deletions

View File

@@ -238,7 +238,6 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) (*CallResult,
if item.Id == int(msg.Id) {
if item.Quantity <= int(msg.Quantity) {
c.Items = append(c.Items[:i], c.Items[i+1:]...)
} else {
item.Quantity -= int(msg.Quantity)
}
@@ -253,13 +252,15 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) (*CallResult,
if !ok {
err = fmt.Errorf("expected RemoveItem")
} else {
for i, item := range c.Items {
items := make([]*CartItem, 0, len(c.Items))
for _, item := range c.Items {
if item.Id == int(msg.Id) {
c.TotalPrice -= item.Price * int64(item.Quantity)
c.Items = append(c.Items[:i], c.Items[i+1:]...)
break
} else {
items = append(items, item)
}
}
c.Items = items
}
case SetDeliveryType:
msg, ok := message.Content.(*messages.SetDelivery)