safe truncation
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user