shopping

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: MIT Imports: 2 Imported by: 0

README

GO SHOPPING CART API

Prerequisites
  • Docker
Installing

Download repository

git clone https://github.com/amelendres/go-shopping-cart

Build

The first installation

make build
HOW TO RUN

ENDPOINTS

  • Add a product to Cart
--header 'Content-Type: application/json' \
--data-raw '{
  "id": "4e45b227-6a79-44ee-8cf0-da21508a4f8a",
  "name": "Dress",
  "price": 299.50,
  "units": 1
}'
  • Get products from cart
curl --location --request GET 'http://localhost:8050/carts/c50bf7b3-95d5-48fa-8b0d-691e3f40c1f9/products' \
--header 'Content-Type: application/json' \

Authors

MIT license

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownCart = errors.New("unknown cart")

Functions

func AssertCartProduct added in v0.3.1

func AssertCartProduct(t *testing.T, cart *Cart, product Product)

func AssertCartProductLines added in v0.3.1

func AssertCartProductLines(t *testing.T, cart *Cart, qty int)

func AssertCartProductQty added in v0.3.1

func AssertCartProductQty(t *testing.T, cart *Cart, product Product, qty Quantity)

func AssertEquals added in v0.3.1

func AssertEquals(t *testing.T, got int, want int)

BASIC ASSERTS

func AssertNoError added in v0.4.1

func AssertNoError(t *testing.T, err error)

func AssertProduct

func AssertProduct(t *testing.T, store *StubCartStore, product Product)

Types

type Cart added in v0.3.1

type Cart struct {
	ID, BuyerID UUID
	Products    Products
}

func NewCart added in v0.3.1

func NewCart(id, buyerId UUID) *Cart

func (*Cart) AddProduct added in v0.3.1

func (c *Cart) AddProduct(product Product)

func (*Cart) GetProducts added in v0.3.1

func (c *Cart) GetProducts() Products

type CartRepository added in v0.3.1

type CartRepository interface {
	Save(cart *Cart) error
	Get(id string) (*Cart, error)
}

type Price added in v0.3.1

type Price float32

type Product

type Product struct {
	ID, Name string
	Price    Price
	Units    Quantity
}

Product stores a product line information

func NewProduct added in v0.3.1

func NewProduct(ID, Name string, Price Price, Units Quantity) Product

func (Product) Equal added in v0.3.1

func (p Product) Equal(other Product) bool

type Products

type Products []Product

Products stores a collection of Products

func (Products) Find

func (p Products) Find(product Product) (int, *Product)

type Quantity added in v0.3.1

type Quantity int

type StubCartStore

type StubCartStore struct {
	Carts []Cart
}

func (*StubCartStore) Get added in v0.3.1

func (s *StubCartStore) Get(id string) (*Cart, error)

func (*StubCartStore) Save added in v0.3.1

func (s *StubCartStore) Save(cart *Cart) error

type UUID added in v0.3.1

type UUID string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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