Documentation
¶
Overview ¶
Package schema defines shopping cart document structures as they might be stored in a Google Firestore or represented in JSON
Index ¶
Constants ¶
const ( // CartCollection names the firestore collection under which all of our documents are stored CartCollection = "carts/" // ItemCollection names the sub-collection of an individual cart in which shopping cart item documents are stored ItemCollection = "/items" // AddressCollection names the sub-collection of an individual cart in which postal address documents are stored AddressCollection = "/addresses" // DeliverAddressDoc names the single delivery address document that may bee associated with the AddressCollection // of a single shopping cart. DeliverAddressDoc = "/delivery" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CartStatus ¶
type CartStatus int32
CartStatus is an enumeration type defining the overall status of a shopping cart
const ( CsUnspecified CartStatus = 0 CsOpen CartStatus = 1 CsCheckedOut CartStatus = 2 CsAbandonedByUser CartStatus = 3 CsAbandonedByTimeout CartStatus = 4 )
type ShoppingCart ¶
type ShoppingCart struct { // Id is a UUID ID in hexadecimal string form - a unique ID for this cart. // This will be set by the cart service when the cart is first created. Id string `firestore:"id" json:"id,omitempty"` // CreationTime is the time at which the cart was created CreationTime time.Time `firestore:"creationTime" json:"creationTime"` // ClosedTime (Optional) is the time at which shopping cart was closed, either // as abandoned or submitted / checked out. ClosedTime time.Time `firestore:"closedTime,omitempty" json:"closedTime,omitempty"` // Status describes the state of the shopping cart (duh!). Status CartStatus `firestore:"status" json:"status"` // Shopper identifies the person who submitted the order Shopper *types.Person `firestore:"shopper" json:"shopper"` // DeliveryAddress is the postal address to which any physical items in the order // are to be delivered. // // NOTE: delivery address is stored as a separate sub-document in the Google Firestore with // the cart reference as their ancestor. DeliveryAddress *types.PostalAddress `firestore:"-" json:"deliveryAddress"` // CartItems is the list of one to many items that make up the potential order. // // NOTE: cart items are stored as separate sub-documents in the Google Firestore with // the cart reference as their ancestor. CartItems []*ShoppingCartItem `firestore:"-" json:"cartItems"` }
ShoppingCart collects the cart items that a shopper is considering purchasing or has purchased. A cart should be considered immutable once purchase has been processed.
It is persisted in the cart firestore collection.
func ShoppingCartFromPB ¶
func ShoppingCartFromPB(pbc *pbcart.ShoppingCart) *ShoppingCart
ShoppingCartFromPB is a factory method that populates a ShoppingCart structure from its protocol buffer equivalent.
func (*ShoppingCart) AsPBShoppingCart ¶
func (c *ShoppingCart) AsPBShoppingCart() *pbcart.ShoppingCart
AsPBShoppingCart returns the protocol buffer representation of this cart.
func (*ShoppingCart) DeliveryAddressPath ¶
func (c *ShoppingCart) DeliveryAddressPath() string
DeliveryAddressPath returns the string representation of the document reference path for the one and only delivery address that can be associated with ths ShoppingCart.
func (*ShoppingCart) ItemCollectionPath ¶
func (c *ShoppingCart) ItemCollectionPath() string
ItemCollectionPath returns the string representation of the collection reference path under which cart items associated with ths ShoppingCart may be stored
func (*ShoppingCart) StoreRefPath ¶
func (c *ShoppingCart) StoreRefPath() string
StoreRefPath returns the string representation of the document reference path for this ShoppingCart.
type ShoppingCartItem ¶
type ShoppingCartItem struct { // Id is a UUID ID in hexadecimal string form - a unique ID for this cart item. Id string `firestore:"id" json:"id,omitempty"` // CartId is a UUID ID in hexadecimal string form - a unique ID for this item's parent cart CartId string `firestore:"cartId" json:"cartId,omitempty"` // ProductCode is the equivalent of a SKU code identifying the type of // product or service being ordered. ProductCode string `firestore:"productCode" json:"productCode"` // Quantity is the number of this item type that is being ordered. Quantity int32 `firestore:"quantity" json:"quantity"` // UnitPrice is the price that the customer was shown for a single item // when they selected the item for their cart UnitPrice *types.Money `firestore:"unitPrice" json:"unitPrice"` }
ShoppingCartItem represents a single entry in an order. An order will contain one to many order items.
func ShoppingCartItemFromPB ¶
func ShoppingCartItemFromPB(pbItem *pbcart.CartItem) *ShoppingCartItem
ShoppingCartItemFromPB is a factory method that returns a ShoppingCartItem representation derived from its protocol buffer equivalent.
func (*ShoppingCartItem) AsPBCartItem ¶
func (item *ShoppingCartItem) AsPBCartItem() *pbcart.CartItem
AsPBCartItem returns the protocol buffer representation of this cart item.
func (*ShoppingCartItem) StoreRefPath ¶
func (item *ShoppingCartItem) StoreRefPath() string
StoreRefPath returns the string representation of the document reference path for this ShoppingCartItem.