update cart model
This commit is contained in:
@@ -25,17 +25,27 @@ func (id *CartId) UnmarshalJSON(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CartItem struct {
|
type CartItem struct {
|
||||||
|
Id int `json:"id"`
|
||||||
Sku string `json:"sku"`
|
Sku string `json:"sku"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Price int64 `json:"price"`
|
Price int64 `json:"price"`
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CartDelivery struct {
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
Price int64 `json:"price"`
|
||||||
|
Items []int `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
type CartGrain struct {
|
type CartGrain struct {
|
||||||
|
lastItemId int
|
||||||
|
lastDeliveryId int
|
||||||
storageMessages []Message
|
storageMessages []Message
|
||||||
Id CartId `json:"id"`
|
Id CartId `json:"id"`
|
||||||
Items []CartItem `json:"items"`
|
Items []CartItem `json:"items"`
|
||||||
TotalPrice int64 `json:"totalPrice"`
|
TotalPrice int64 `json:"totalPrice"`
|
||||||
|
Deliveries []string `json:"deliveries,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Grain interface {
|
type Grain interface {
|
||||||
@@ -127,7 +137,9 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) ([]byte, erro
|
|||||||
if !ok {
|
if !ok {
|
||||||
err = fmt.Errorf("expected AddItem")
|
err = fmt.Errorf("expected AddItem")
|
||||||
} else {
|
} else {
|
||||||
|
c.lastItemId++
|
||||||
c.Items = append(c.Items, CartItem{
|
c.Items = append(c.Items, CartItem{
|
||||||
|
Id: c.lastItemId,
|
||||||
Sku: msg.Sku,
|
Sku: msg.Sku,
|
||||||
Name: msg.Name,
|
Name: msg.Name,
|
||||||
Price: msg.Price,
|
Price: msg.Price,
|
||||||
@@ -135,6 +147,12 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) ([]byte, erro
|
|||||||
})
|
})
|
||||||
c.TotalPrice += msg.Price
|
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:
|
default:
|
||||||
err = fmt.Errorf("unknown message type %d", message.Type)
|
err = fmt.Errorf("unknown message type %d", message.Type)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AddRequestType = 1
|
AddRequestType = 1
|
||||||
AddItemType = 2
|
AddItemType = 2
|
||||||
|
AddDeliveryType = 3
|
||||||
|
RemoveItemType = 4
|
||||||
|
RemoveDeliveryType = 5
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,8 +14,21 @@ message AddItem {
|
|||||||
string Image = 6;
|
string Image = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Negotiate {
|
message RemoteItem {
|
||||||
repeated Host host = 1;
|
int64 Id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ChangeQuantity {
|
||||||
|
int32 Quantity = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SetDelivery {
|
||||||
|
string Provider = 1;
|
||||||
|
repeated int64 Items = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RemoveDelivery {
|
||||||
|
int64 Id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user