diff --git a/cart-grain.go b/cart-grain.go index 96f1a23..34bee03 100644 --- a/cart-grain.go +++ b/cart-grain.go @@ -25,17 +25,27 @@ func (id *CartId) UnmarshalJSON(data []byte) error { } type CartItem struct { + Id int `json:"id"` Sku string `json:"sku"` Name string `json:"name"` Price int64 `json:"price"` Image string `json:"image"` } +type CartDelivery struct { + Provider string `json:"provider"` + Price int64 `json:"price"` + Items []int `json:"items"` +} + type CartGrain struct { + lastItemId int + lastDeliveryId int storageMessages []Message Id CartId `json:"id"` Items []CartItem `json:"items"` TotalPrice int64 `json:"totalPrice"` + Deliveries []string `json:"deliveries,omitempty"` } type Grain interface { @@ -127,7 +137,9 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) ([]byte, erro if !ok { err = fmt.Errorf("expected AddItem") } else { + c.lastItemId++ c.Items = append(c.Items, CartItem{ + Id: c.lastItemId, Sku: msg.Sku, Name: msg.Name, Price: msg.Price, @@ -135,6 +147,12 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) ([]byte, erro }) c.TotalPrice += msg.Price } + case RemoveItemType: + //msg, ok := message.Content.(*messages.RemoveItem) + case AddDeliveryType: + c.lastDeliveryId++ + //msg, ok := message.Content.(*messages.AddDelivery) + case RemoveDeliveryType: default: err = fmt.Errorf("unknown message type %d", message.Type) } diff --git a/message-types.go b/message-types.go index 9d5aac6..201bbb5 100644 --- a/message-types.go +++ b/message-types.go @@ -1,6 +1,9 @@ package main const ( - AddRequestType = 1 - AddItemType = 2 + AddRequestType = 1 + AddItemType = 2 + AddDeliveryType = 3 + RemoveItemType = 4 + RemoveDeliveryType = 5 ) diff --git a/proto/messages.proto b/proto/messages.proto index 8389536..ffe2489 100644 --- a/proto/messages.proto +++ b/proto/messages.proto @@ -14,8 +14,21 @@ message AddItem { string Image = 6; } -message Negotiate { - repeated Host host = 1; +message RemoteItem { + int64 Id = 1; +} + +message ChangeQuantity { + int32 Quantity = 1; +} + +message SetDelivery { + string Provider = 1; + repeated int64 Items = 2; +} + +message RemoveDelivery { + int64 Id = 1; }