domain

package
v0.0.0-...-76fafce Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 7 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

func Registrations

func Registrations(reg registry.Registry) error

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 (*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() (ddd.Event, error)

func (*Basket) Checkout

func (b *Basket) Checkout(paymentID string) (ddd.Event, 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) Start

func (b *Basket) Start(customerID string) (ddd.Event, error)

func (*Basket) ToSnapshot

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

type BasketCanceled

type BasketCanceled struct{}

func (BasketCanceled) Key

func (BasketCanceled) Key() string

type BasketCheckedOut

type BasketCheckedOut struct {
	PaymentID string
}

func (BasketCheckedOut) Key

func (BasketCheckedOut) Key() string

type BasketItemAdded

type BasketItemAdded struct {
	Item Item
}

func (BasketItemAdded) Key

func (BasketItemAdded) Key() string

type BasketItemRemoved

type BasketItemRemoved struct {
	ProductID string
	Quantity  int
}

func (BasketItemRemoved) Key

func (BasketItemRemoved) Key() string

type BasketRepository

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

the Load method is not defined in the BasketRepository interface itself. The Load method is only defined in the concrete implementations of the BasketRepository interface, such as FakeBasketRepository.

The purpose of the BasketRepository interface is to define a set of methods that must be implemented by any concrete type that implements the interface. In this case, the BasketRepository interface defines the Load and Save methods, which must be implemented by any concrete type that implements the BasketRepository interface.

type BasketStarted

type BasketStarted struct {
	CustomerID string
}

func (BasketStarted) Key

func (BasketStarted) Key() string

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 FakeBasketRepository

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

used in testing code to simulate different scenarios

func NewFakeBasketRepository

func NewFakeBasketRepository() *FakeBasketRepository

func (*FakeBasketRepository) Load

func (r *FakeBasketRepository) Load(ctx context.Context, basketID string) (*Basket, error)

func (*FakeBasketRepository) Reset

func (r *FakeBasketRepository) Reset(baskets ...*Basket)

func (*FakeBasketRepository) Save

func (r *FakeBasketRepository) Save(ctx context.Context, basket *Basket) error

type FakeProductCacheRepository

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

func NewFakeProductCacheRepository

func NewFakeProductCacheRepository() *FakeProductCacheRepository

func (*FakeProductCacheRepository) Add

func (r *FakeProductCacheRepository) Add(ctx context.Context, productID, storeID, name string, price float64) error

func (*FakeProductCacheRepository) Find

func (r *FakeProductCacheRepository) Find(ctx context.Context, productID string) (*Product, error)

func (*FakeProductCacheRepository) Rebrand

func (r *FakeProductCacheRepository) Rebrand(ctx context.Context, productID, name string) error

func (*FakeProductCacheRepository) Remove

func (r *FakeProductCacheRepository) Remove(ctx context.Context, productID string) error

func (*FakeProductCacheRepository) Reset

func (r *FakeProductCacheRepository) Reset(products ...*Product)

func (*FakeProductCacheRepository) UpdatePrice

func (r *FakeProductCacheRepository) UpdatePrice(ctx context.Context, productID string, delta float64) error

type FakeStoreCacheRepository

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

func NewFakeStoreCacheRepository

func NewFakeStoreCacheRepository() *FakeStoreCacheRepository

func (*FakeStoreCacheRepository) Add

func (r *FakeStoreCacheRepository) Add(ctx context.Context, storeID, name string) error

func (*FakeStoreCacheRepository) Find

func (r *FakeStoreCacheRepository) Find(ctx context.Context, storeID string) (*Store, error)

func (*FakeStoreCacheRepository) Rename

func (r *FakeStoreCacheRepository) Rename(ctx context.Context, storeID, name string) error

func (*FakeStoreCacheRepository) Reset

func (r *FakeStoreCacheRepository) Reset(stores ...*Store)

type Item

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

type MockBasketRepository

type MockBasketRepository struct {
	mock.Mock
}

MockBasketRepository is an autogenerated mock type for the BasketRepository type

func NewMockBasketRepository

func NewMockBasketRepository(t mockConstructorTestingTNewMockBasketRepository) *MockBasketRepository

NewMockBasketRepository creates a new instance of MockBasketRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockBasketRepository) Load

func (_m *MockBasketRepository) Load(ctx context.Context, basketID string) (*Basket, error)

Load provides a mock function with given fields: ctx, basketID

func (*MockBasketRepository) Save

func (_m *MockBasketRepository) Save(ctx context.Context, basket *Basket) error

Save provides a mock function with given fields: ctx, basket

type MockProductCacheRepository

type MockProductCacheRepository struct {
	mock.Mock
}

MockProductCacheRepository is an autogenerated mock type for the ProductCacheRepository type

func NewMockProductCacheRepository

func NewMockProductCacheRepository(t mockConstructorTestingTNewMockProductCacheRepository) *MockProductCacheRepository

NewMockProductCacheRepository creates a new instance of MockProductCacheRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockProductCacheRepository) Add

func (_m *MockProductCacheRepository) Add(ctx context.Context, productID string, storeID string, name string, price float64) error

Add provides a mock function with given fields: ctx, productID, storeID, name, price

func (*MockProductCacheRepository) Find

func (_m *MockProductCacheRepository) Find(ctx context.Context, productID string) (*Product, error)

Find provides a mock function with given fields: ctx, productID

func (*MockProductCacheRepository) Rebrand

func (_m *MockProductCacheRepository) Rebrand(ctx context.Context, productID string, name string) error

Rebrand provides a mock function with given fields: ctx, productID, name

func (*MockProductCacheRepository) Remove

func (_m *MockProductCacheRepository) Remove(ctx context.Context, productID string) error

Remove provides a mock function with given fields: ctx, productID

func (*MockProductCacheRepository) UpdatePrice

func (_m *MockProductCacheRepository) UpdatePrice(ctx context.Context, productID string, delta float64) error

UpdatePrice provides a mock function with given fields: ctx, productID, delta

type MockProductRepository

type MockProductRepository struct {
	mock.Mock
}

MockProductRepository is an autogenerated mock type for the ProductRepository type

func NewMockProductRepository

func NewMockProductRepository(t mockConstructorTestingTNewMockProductRepository) *MockProductRepository

NewMockProductRepository creates a new instance of MockProductRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockProductRepository) Find

func (_m *MockProductRepository) Find(ctx context.Context, productID string) (*Product, error)

Find provides a mock function with given fields: ctx, productID

type MockStoreCacheRepository

type MockStoreCacheRepository struct {
	mock.Mock
}

MockStoreCacheRepository is an autogenerated mock type for the StoreCacheRepository type

func NewMockStoreCacheRepository

func NewMockStoreCacheRepository(t mockConstructorTestingTNewMockStoreCacheRepository) *MockStoreCacheRepository

NewMockStoreCacheRepository creates a new instance of MockStoreCacheRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockStoreCacheRepository) Add

func (_m *MockStoreCacheRepository) Add(ctx context.Context, storeID string, name string) error

Add provides a mock function with given fields: ctx, storeID, name

func (*MockStoreCacheRepository) Find

func (_m *MockStoreCacheRepository) Find(ctx context.Context, storeID string) (*Store, error)

Find provides a mock function with given fields: ctx, storeID

func (*MockStoreCacheRepository) Rename

func (_m *MockStoreCacheRepository) Rename(ctx context.Context, storeID string, name string) error

Rename provides a mock function with given fields: ctx, storeID, name

type MockStoreRepository

type MockStoreRepository struct {
	mock.Mock
}

MockStoreRepository is an autogenerated mock type for the StoreRepository type

func NewMockStoreRepository

func NewMockStoreRepository(t mockConstructorTestingTNewMockStoreRepository) *MockStoreRepository

NewMockStoreRepository creates a new instance of MockStoreRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockStoreRepository) Find

func (_m *MockStoreRepository) Find(ctx context.Context, storeID string) (*Store, error)

Find provides a mock function with given fields: ctx, storeID

type Product

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

type ProductCacheRepository

type ProductCacheRepository interface {
	Add(ctx context.Context, productID, storeID, name string, price float64) error
	Rebrand(ctx context.Context, productID, name string) error
	UpdatePrice(ctx context.Context, productID string, delta float64) error
	Remove(ctx context.Context, productID string) error
	ProductRepository
}

type ProductRepository

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

type Store

type Store struct {
	ID   string
	Name string
}

type StoreCacheRepository

type StoreCacheRepository interface {
	Add(ctx context.Context, storeID, name string) error
	Rename(ctx context.Context, storeID, name string) error
	StoreRepository
}

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