cart

package
v0.0.0-...-8bff5d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

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.

func New

func New(id string) *Cart

New returns a cart with the default values.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler manages cart endpoints.

func NewHandler

func NewHandler(service Service, db *sqlx.DB, cache *memcache.Client) Handler

NewHandler returns a new cart handler.

func (*Handler) Add

func (h *Handler) Add() http.HandlerFunc

Add appends a product to the cart.

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.

func NewService

func NewService(db *sqlx.DB, mc *memcache.Client) Service

NewService returns a new cart service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL