cart

package
v0.0.0-...-9a5c20e Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-3-Clause Imports: 3 Imported by: 1

README

cart

import "github.com/blueprint-uservices/blueprint/examples/sockshop/workflow/cart"

Package cart implements the SockShop cart microservice.

Index

type CartService

The CartService interface

type CartService interface {
    // Get all items in a customer's cart.  A customer might not have a cart,
    // in which case the empty list is returned.  customerID can be a userID
    // for a logged in user, or a sessionID for an anonymous user.
    GetCart(ctx context.Context, customerID string) ([]Item, error)

    // Delete a customer's cart
    DeleteCart(ctx context.Context, customerID string) error

    // Merge two carts.  Used when an anonymous customer logs in
    MergeCarts(ctx context.Context, customerID, sessionID string) error

    // Get a specific item from a customer's cart
    GetItem(ctx context.Context, customerID string, itemID string) (Item, error)

    // Add an item to a customer's cart.
    // If the item already exists in the cart, then the total quantity is
    // updated to reflect the combined total.
    // Returns the current state of the item in the customer's cart.
    AddItem(ctx context.Context, customerID string, item Item) (Item, error)

    // Remove an item from the customer's cart
    RemoveItem(ctx context.Context, customerID, itemID string) error

    // Updates an item in the customer's cart to the value provided.
    UpdateItem(ctx context.Context, customerID string, item Item) error
}

func NewCartService
func NewCartService(ctx context.Context, db backend.NoSQLDatabase) (CartService, error)

Creates a CartService instance that persists cart data in the provided db

type Item

A cart item is just an item ID and a quantity. The catalogue service is responsible for managing the actual items.

type Item struct {
    ID        string  // Item ID will correspond to the ID used by the catalogue service
    Quantity  int     // The quantity of this item in the car
    UnitPrice float32 // The price of the item
}

Generated by gomarkdoc

Documentation

Overview

Package cart implements the SockShop cart microservice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CartService

type CartService interface {
	// Get all items in a customer's cart.  A customer might not have a cart,
	// in which case the empty list is returned.  customerID can be a userID
	// for a logged in user, or a sessionID for an anonymous user.
	GetCart(ctx context.Context, customerID string) ([]Item, error)

	// Delete a customer's cart
	DeleteCart(ctx context.Context, customerID string) error

	// Merge two carts.  Used when an anonymous customer logs in
	MergeCarts(ctx context.Context, customerID, sessionID string) error

	// Get a specific item from a customer's cart
	GetItem(ctx context.Context, customerID string, itemID string) (Item, error)

	// Add an item to a customer's cart.
	// If the item already exists in the cart, then the total quantity is
	// updated to reflect the combined total.
	// Returns the current state of the item in the customer's cart.
	AddItem(ctx context.Context, customerID string, item Item) (Item, error)

	// Remove an item from the customer's cart
	RemoveItem(ctx context.Context, customerID, itemID string) error

	// Updates an item in the customer's cart to the value provided.
	UpdateItem(ctx context.Context, customerID string, item Item) error
}

The CartService interface

func NewCartService

func NewCartService(ctx context.Context, db backend.NoSQLDatabase) (CartService, error)

Creates a CartService instance that persists cart data in the provided db

type Item

type Item struct {
	ID        string  // Item ID will correspond to the ID used by the catalogue service
	Quantity  int     // The quantity of this item in the car
	UnitPrice float32 // The price of the item
}

A cart item is just an item ID and a quantity. The catalogue service is responsible for managing the actual items.

Jump to

Keyboard shortcuts

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