domain

package
v0.0.0-...-3a9fddd Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBasketHasNoItems         = errors.Wrap(errors.ErrBadRequest, "the basket has no items")
	ErrBasketCannotBeModified   = errors.Wrap(errors.ErrBadRequest, "the basket cannot be modified")
	ErrBasketCannotBeCancelled  = errors.Wrap(errors.ErrBadRequest, "the basket cannot be cancelled")
	ErrQuantityCannotBeNegative = errors.Wrap(errors.ErrBadRequest, "the item quantity cannot be negative")
	ErrBasketIDCannotBeBlank    = errors.Wrap(errors.ErrBadRequest, "the basket id cannot be blank")
	ErrPaymentIDCannotBeBlank   = errors.Wrap(errors.ErrBadRequest, "the payment id cannot be blank")
	ErrCustomerIDCannotBeBlank  = errors.Wrap(errors.ErrBadRequest, "the customer id cannot be blank")
)

Functions

This section is empty.

Types

type Basket

type Basket struct {
	ID         string
	CustomerID string
	PaymentID  string
	Items      []Item
	Status     BasketStatus
}

func StartBasket

func StartBasket(id, customerID string) (*Basket, error)

func (*Basket) AddItem

func (b *Basket) AddItem(store *Store, product *Product, quantity int) error

func (*Basket) Cancel

func (b *Basket) Cancel() error

func (*Basket) Checkout

func (b *Basket) Checkout(paymentID string) error

func (Basket) IsCancellable

func (b Basket) IsCancellable() bool

func (Basket) IsOpen

func (b Basket) IsOpen() bool

func (*Basket) RemoveItem

func (b *Basket) RemoveItem(product *Product, quantity int) error

type BasketRepository

type BasketRepository interface {
	Find(ctx context.Context, basketID string) (*Basket, error)
	Save(ctx context.Context, basket *Basket) error
	Update(ctx context.Context, basket *Basket) error
}

type BasketStatus

type BasketStatus string
const (
	BasketUnknown    BasketStatus = ""
	BasketOpen       BasketStatus = "open"
	BasketCancelled  BasketStatus = "cancelled"
	BasketCheckedOut BasketStatus = "checked_out"
)

func (BasketStatus) String

func (s BasketStatus) String() string

type Item

type Item struct {
	StoreID      string
	ProductID    string
	StoreName    string
	ProductName  string
	ProductPrice float64
	Quantity     int
}

type OrderRepository

type OrderRepository interface {
	Save(ctx context.Context, basket *Basket) (string, error)
}

type Product

type Product struct {
	ID      string
	StoreID string
	Name    string
	Price   float64
}

type ProductRepository

type ProductRepository interface {
	Find(ctx context.Context, productID string) (*Product, error)
}

type Store

type Store struct {
	ID       string
	Name     string
	Location string
}

type StoreRepository

type StoreRepository interface {
	Find(ctx context.Context, storeID string) (*Store, error)
}

Jump to

Keyboard shortcuts

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