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: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BasketStartedEvent     = "baskets.BasketStarted"
	BasketItemAddedEvent   = "baskets.BasketItemAdded"
	BasketItemRemovedEvent = "baskets.BasketItemRemoved"
	BasketCanceledEvent    = "baskets.BasketCanceled"
	BasketCheckedOutEvent  = "baskets.BasketCheckedOut"
)
View Source
const BasketAggregate = "baskets.Basket"

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 {
	es.Aggregate
	CustomerID string
	PaymentID  string
	Items      map[string]Item
	Status     BasketStatus
}

func NewBasket

func NewBasket(id string) *Basket

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) ApplyEvent

func (b *Basket) ApplyEvent(event ddd.Event) error

func (*Basket) ApplySnapshot

func (b *Basket) ApplySnapshot(snapshot es.Snapshot) 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) Key

func (Basket) Key() string

func (*Basket) RemoveItem

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

func (*Basket) ToSnapshot

func (b *Basket) ToSnapshot() es.Snapshot

type BasketCanceled

type BasketCanceled struct{}

func (BasketCanceled) Key

func (BasketCanceled) Key() string

Key implements registry.Registerable

type BasketCheckedOut

type BasketCheckedOut struct {
	PaymentID  string
	CustomerID string
	Items      map[string]Item
}

func (BasketCheckedOut) Key

func (BasketCheckedOut) Key() string

Key implements registry.Registerable

type BasketItemAdded

type BasketItemAdded struct {
	Item Item
}

func (BasketItemAdded) Key

func (BasketItemAdded) Key() string

Key implements registry.Registerable

type BasketItemRemoved

type BasketItemRemoved struct {
	ProductID string
	Quantity  int
}

func (BasketItemRemoved) Key

func (BasketItemRemoved) Key() string

Key implements registry.Registerable

type BasketRepository

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

type BasketStarted

type BasketStarted struct {
	CustomerID string
}

func (BasketStarted) Key

func (BasketStarted) Key() string

Key implements registry.Registerable

type BasketStatus

type BasketStatus string
const (
	BasketUnknown      BasketStatus = ""
	BasketIsOpen       BasketStatus = "open"
	BasketIsCanceled   BasketStatus = "canceled"
	BasketIsCheckedOut BasketStatus = "checked_out"
)

func ToBasketStatus

func ToBasketStatus(status string) BasketStatus

func (BasketStatus) String

func (s BasketStatus) String() string

type BasketV1

type BasketV1 struct {
	CustomerID string
	PaymentID  string
	Items      map[string]Item
	Status     BasketStatus
}

func (BasketV1) SnapshotName

func (BasketV1) SnapshotName() 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, paymentID, customerID string, basketItems map[string]Item) (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