Documentation ¶
Index ¶
- type Cart
- type CartItem
- type CartItemProductMessage
- type CartRepository
- func (c *CartRepository) AddToCart(userID string, productID string) (string, error)
- func (c *CartRepository) FindCart(userID string) (*Cart, error)
- func (c *CartRepository) FlushCart(userID string)
- func (c *CartRepository) RemoveFromCart(itemID, userID string) error
- func (c *CartRepository) UpdateCartItem(message CartItemProductMessage)
- type MockCartRepository
- func (c *MockCartRepository) AddToCart(userID string, productID string) (string, error)
- func (c *MockCartRepository) FindCart(userID string) (*Cart, error)
- func (c *MockCartRepository) FlushCart(userID string)
- func (c *MockCartRepository) RemoveFromCart(itemID, userID string) error
- func (c *MockCartRepository) UpdateCartItem(message CartItemProductMessage)
- type Repository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cart ¶
type Cart struct { ID string `bson:"_id,omitempty"` UserID string `bson:"user_id,omitempty"` Active bool `bson:"active,omitempty"` Items []CartItem `bson:"items,omitempty"` }
Cart struct represents cart document in database.
func (*Cart) ConvertToGrpcModel ¶
func (c *Cart) ConvertToGrpcModel() *cart_grpc.CartContentResponse
ConvertToGrpcModel converts Cart struct to gRPC compatible struct.
type CartItem ¶
type CartItem struct { ID string `bson:"_id,omitempty"` ProductID string `bson:"product_id,omitempty"` Title string `bson:"title,omitempty"` Description string `bson:"description,omitempty"` Image string `bson:"image,omitempty"` Price float32 `bson:"price,omitempty"` }
CartItem struct represents cart items in a cart.
func (*CartItem) ConvertToGrpcModel ¶
ConvertToGrpcModel converts cart item to gRPC compatible struct.
type CartItemProductMessage ¶
type CartItemProductMessage struct { ProductID string `json:"product_id"` CartItemID string `json:"cart_item_id"` Title string `json:"title"` Description string `json:"description"` Image string `json:"image"` Price float32 `json:"price"` }
CartItemProductMessage struct represents update cart function call parameter.
type CartRepository ¶
CartRepository connects to Mongo.
func (*CartRepository) AddToCart ¶
func (c *CartRepository) AddToCart(userID string, productID string) (string, error)
AddToCart adds product to cart.
func (*CartRepository) FindCart ¶
func (c *CartRepository) FindCart(userID string) (*Cart, error)
FindCart returns cart for given userID. If no document found, return empty cart.
func (*CartRepository) FlushCart ¶
func (c *CartRepository) FlushCart(userID string)
FlushCart removes all items in cart.
func (*CartRepository) RemoveFromCart ¶
func (c *CartRepository) RemoveFromCart(itemID, userID string) error
RemoveFromCart removes given item from cart.
func (*CartRepository) UpdateCartItem ¶
func (c *CartRepository) UpdateCartItem(message CartItemProductMessage)
UpdateCartItem updates cart item's title, description, price and image. Cart item contains product ID at creation. Other fields populated from Redis pub/sub.
type MockCartRepository ¶
type MockCartRepository struct { ErrorOnAdd bool ErrorOnDisplay bool ErrorOnDelete bool Storage map[string]*Cart }
func (*MockCartRepository) AddToCart ¶
func (c *MockCartRepository) AddToCart(userID string, productID string) (string, error)
func (*MockCartRepository) FindCart ¶
func (c *MockCartRepository) FindCart(userID string) (*Cart, error)
func (*MockCartRepository) FlushCart ¶
func (c *MockCartRepository) FlushCart(userID string)
func (*MockCartRepository) RemoveFromCart ¶
func (c *MockCartRepository) RemoveFromCart(itemID, userID string) error
func (*MockCartRepository) UpdateCartItem ¶
func (c *MockCartRepository) UpdateCartItem(message CartItemProductMessage)
type Repository ¶
type Repository interface { FindCart(userID string) (*Cart, error) AddToCart(userID string, productID string) (string, error) RemoveFromCart(itemID, userID string) error FlushCart(userID string) UpdateCartItem(message CartItemProductMessage) }
Repository is an interface that contains required functionalities by handlers and event handlers.