Documentation ¶
Index ¶
- type Cart
- type Handler
- func (h *Handler) Add() http.HandlerFunc
- func (h *Handler) Checkout() http.HandlerFunc
- func (h *Handler) FilterBy() http.HandlerFunc
- func (h *Handler) Get() http.HandlerFunc
- func (h *Handler) Products() http.HandlerFunc
- func (h *Handler) Remove() http.HandlerFunc
- func (h *Handler) Reset() http.HandlerFunc
- func (h *Handler) Size() http.HandlerFunc
- type Product
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cart ¶
type Cart struct { ID string `json:"id,omitempty"` // Counter contains the quantity of products placed in the cart Counter zero.Int `json:"counter,omitempty"` // 1000 = 1kg Weight zero.Int `json:"weight,omitempty"` // This field should be used as a percentage Discount zero.Int `json:"discount,omitempty"` // This field should be used as a percentage Taxes zero.Int `json:"taxes,omitempty"` Subtotal zero.Int `json:"subtotal,omitempty"` Total zero.Int `json:"total,omitempty"` Products []Product `json:"products,omitempty"` }
Cart represents a temporary record of items that the customer selected for purchase.
Amounts to be provided in a currency’s smallest unit. 100 = 1 USD.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages cart endpoints.
func NewHandler ¶
NewHandler returns a new cart handler.
func (*Handler) Checkout ¶
func (h *Handler) Checkout() http.HandlerFunc
Checkout returns the final purchase.
func (*Handler) FilterBy ¶
func (h *Handler) FilterBy() http.HandlerFunc
FilterBy returns the products filtered by the field provided.
func (*Handler) Get ¶
func (h *Handler) Get() http.HandlerFunc
Get returns the cart in a JSON format.
func (*Handler) Products ¶
func (h *Handler) Products() http.HandlerFunc
Products retrieves cart products.
func (*Handler) Remove ¶
func (h *Handler) Remove() http.HandlerFunc
Remove takes out a product from the shopping cart.
func (*Handler) Reset ¶
func (h *Handler) Reset() http.HandlerFunc
Reset resets the cart to its default state.
func (*Handler) Size ¶
func (h *Handler) Size() http.HandlerFunc
Size returns the size of the shopping cart.
type Product ¶
type Product struct { ID zero.String `json:"id,omitempty" validate:"uuid4_rfc4122"` CartID zero.String `json:"cart_id,omitempty" db:"cart_id"` Quantity zero.Int `json:"quantity,omitempty" validate:"required,min=1"` }
Product represents a product that has been added to the cart.
type Service ¶
type Service interface { Add(ctx context.Context, cartProduct Product) error Checkout(ctx context.Context, cartID string) (int64, error) Create(ctx context.Context, cartID string) error Delete(ctx context.Context, cartID string) error FilterBy(ctx context.Context, cartID, field, args string) ([]product.Product, error) Get(ctx context.Context, cartID string) (Cart, error) CartProduct(ctx context.Context, cartID, productID string) (Product, error) CartProducts(ctx context.Context, cartID string) ([]Product, error) Remove(ctx context.Context, cartID string, pID string, quantity int64) error Reset(ctx context.Context, cartID string) error Size(ctx context.Context, cartID string) (int64, error) }
Service contains order functionalities.