Documentation ¶
Index ¶
- Constants
- Variables
- func Registrations(reg registry.Registry) error
- type Basket
- func (b *Basket) AddItem(store *Store, product *Product, quantity int) error
- func (b *Basket) ApplyEvent(event ddd.Event) error
- func (b *Basket) ApplySnapshot(snapshot es.Snapshot) error
- func (b *Basket) Cancel() (ddd.Event, error)
- func (b *Basket) Checkout(paymentID string) (ddd.Event, error)
- func (b Basket) IsCancellable() bool
- func (b Basket) IsOpen() bool
- func (Basket) Key() string
- func (b *Basket) RemoveItem(product *Product, quantity int) error
- func (b *Basket) Start(customerID string) (ddd.Event, error)
- func (b *Basket) ToSnapshot() es.Snapshot
- type BasketCanceled
- type BasketCheckedOut
- type BasketItemAdded
- type BasketItemRemoved
- type BasketRepository
- type BasketStarted
- type BasketStatus
- type BasketV1
- type FakeBasketRepository
- type FakeProductCacheRepository
- func (r *FakeProductCacheRepository) Add(ctx context.Context, productID, storeID, name string, price float64) error
- func (r *FakeProductCacheRepository) Find(ctx context.Context, productID string) (*Product, error)
- func (r *FakeProductCacheRepository) Rebrand(ctx context.Context, productID, name string) error
- func (r *FakeProductCacheRepository) Remove(ctx context.Context, productID string) error
- func (r *FakeProductCacheRepository) Reset(products ...*Product)
- func (r *FakeProductCacheRepository) UpdatePrice(ctx context.Context, productID string, delta float64) error
- type FakeStoreCacheRepository
- func (r *FakeStoreCacheRepository) Add(ctx context.Context, storeID, name string) error
- func (r *FakeStoreCacheRepository) Find(ctx context.Context, storeID string) (*Store, error)
- func (r *FakeStoreCacheRepository) Rename(ctx context.Context, storeID, name string) error
- func (r *FakeStoreCacheRepository) Reset(stores ...*Store)
- type Item
- type MockBasketRepository
- type MockProductCacheRepository
- func (_m *MockProductCacheRepository) Add(ctx context.Context, productID string, storeID string, name string, ...) error
- func (_m *MockProductCacheRepository) Find(ctx context.Context, productID string) (*Product, error)
- func (_m *MockProductCacheRepository) Rebrand(ctx context.Context, productID string, name string) error
- func (_m *MockProductCacheRepository) Remove(ctx context.Context, productID string) error
- func (_m *MockProductCacheRepository) UpdatePrice(ctx context.Context, productID string, delta float64) error
- type MockProductRepository
- type MockStoreCacheRepository
- type MockStoreRepository
- type Product
- type ProductCacheRepository
- type ProductRepository
- type Store
- type StoreCacheRepository
- type StoreRepository
Constants ¶
const ( BasketStartedEvent = "baskets.BasketStarted" BasketItemAddedEvent = "baskets.BasketItemAdded" BasketItemRemovedEvent = "baskets.BasketItemRemoved" BasketCanceledEvent = "baskets.BasketCanceled" BasketCheckedOutEvent = "baskets.BasketCheckedOut" )
const BasketAggregate = "baskets.Basket"
Variables ¶
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 ¶
Types ¶
type Basket ¶
type Basket struct { es.Aggregate CustomerID string PaymentID string Items map[string]Item Status BasketStatus }
func (Basket) IsCancellable ¶
func (*Basket) ToSnapshot ¶
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 ¶
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 ¶
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) Reset ¶
func (r *FakeBasketRepository) Reset(baskets ...*Basket)
type FakeProductCacheRepository ¶
type FakeProductCacheRepository struct {
// contains filtered or unexported fields
}
func NewFakeProductCacheRepository ¶
func NewFakeProductCacheRepository() *FakeProductCacheRepository
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 ¶
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) Rename ¶
func (r *FakeStoreCacheRepository) Rename(ctx context.Context, storeID, name string) error
func (*FakeStoreCacheRepository) Reset ¶
func (r *FakeStoreCacheRepository) Reset(stores ...*Store)
type MockBasketRepository ¶
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.
type MockProductCacheRepository ¶
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 ¶
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 ¶
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.
type MockStoreCacheRepository ¶
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 ¶
Add provides a mock function with given fields: ctx, storeID, name
type MockStoreRepository ¶
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.
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 StoreCacheRepository ¶
Source Files ¶
- basket.go
- basket_events.go
- basket_repository.go
- basket_snapshots.go
- basket_status.go
- fake_basket_repository.go
- fake_product_cache_repository.go
- fake_store_cache_repository.go
- item.go
- mock_basket_repository.go
- mock_product_cache_repository.go
- mock_product_repository.go
- mock_store_cache_repository.go
- mock_store_repository.go
- product.go
- product_cache_repository.go
- product_repository.go
- registrations.go
- store.go
- store_cache_repository.go
- store_repository.go