Documentation ¶
Index ¶
- Variables
- type AllocatedQtys
- type AvailableSources
- type AvailableSourcesProvider
- type DefaultSourcingService
- func (d *DefaultSourcingService) AllocateItems(ctx context.Context, decoratedCart *decorator.DecoratedCart) (ItemAllocations, error)
- func (d *DefaultSourcingService) GetAvailableSources(ctx context.Context, product domain.BasicProduct, ...) (AvailableSources, error)
- func (d *DefaultSourcingService) Inject(logger flamingo.Logger, dep ...) *DefaultSourcingService
- type ItemAllocation
- type ItemAllocations
- type ItemID
- type Source
- type SourcingService
- type StockProvider
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInsufficientSourceQty - use to indicate that the requested qty exceeds the available qty ErrInsufficientSourceQty = errors.New("Available Source Qty insufficient") // ErrNoSourceAvailable - use to indicate that no source for item is available at all ErrNoSourceAvailable = errors.New("No Available Source Qty") // ErrNeedMoreDetailsSourceCannotBeDetected - use to indicate that informations are missing to determine a source ErrNeedMoreDetailsSourceCannotBeDetected = errors.New("Source cannot be detected") )
Functions ¶
This section is empty.
Types ¶
type AllocatedQtys ¶
AllocatedQtys represents the allocated Qty per source
type AvailableSources ¶
AvailableSources is the result value object containing the available Qty per Source
func (AvailableSources) QtySum ¶
func (s AvailableSources) QtySum() int
QtySum returns the sum of all sourced items
func (AvailableSources) Reduce ¶
func (s AvailableSources) Reduce(reducedBy AllocatedQtys) AvailableSources
Reduce returns new AvailableSources reduced by the given AvailableSources
type AvailableSourcesProvider ¶
type AvailableSourcesProvider interface {
GetPossibleSources(ctx context.Context, product domain.BasicProduct, deliveryInfo *cartDomain.DeliveryInfo) ([]Source, error)
}
AvailableSourcesProvider interface for DefaultSourcingService
type DefaultSourcingService ¶
type DefaultSourcingService struct {
// contains filtered or unexported fields
}
DefaultSourcingService provides a default implementation of the SourcingService interface. This default implementation is used unless a project overrides the interface binding.
func (*DefaultSourcingService) AllocateItems ¶
func (d *DefaultSourcingService) AllocateItems(ctx context.Context, decoratedCart *decorator.DecoratedCart) (ItemAllocations, error)
AllocateItems - see description in Interface
func (*DefaultSourcingService) GetAvailableSources ¶
func (d *DefaultSourcingService) GetAvailableSources(ctx context.Context, product domain.BasicProduct, deliveryInfo *cartDomain.DeliveryInfo, decoratedCart *decorator.DecoratedCart) (AvailableSources, error)
GetAvailableSources - see description in Interface
func (*DefaultSourcingService) Inject ¶
func (d *DefaultSourcingService) Inject( logger flamingo.Logger, dep *struct { AvailableSourcesProvider AvailableSourcesProvider `inject:",optional"` StockProvider StockProvider `inject:",optional"` }, ) *DefaultSourcingService
Inject the dependencies
type ItemAllocation ¶
type ItemAllocation struct { AllocatedQtys AllocatedQtys Error error }
ItemAllocation info
type ItemAllocations ¶
type ItemAllocations map[ItemID]ItemAllocation
ItemAllocations represents the allocated Qtys per itemID
type Source ¶
type Source struct { // LocationCode identifies the warehouse or stock location LocationCode string // ExternalLocationCode identifies the source location in an external system ExternalLocationCode string }
Source descriptor for a single location
type SourcingService ¶
type SourcingService interface { // AllocateItems returns Sources for the given item in the given cart // e.g. use this during place order to know // throws ErrInsufficientSourceQty if not enough stock is available for the amount of items in the cart // throws ErrNoSourceAvailable if no source is available at all for one of the items // throws ErrNeedMoreDetailsSourceCannotBeDetected if information on the cart (or delivery is missing) AllocateItems(ctx context.Context, decoratedCart *decorator.DecoratedCart) (ItemAllocations, error) // GetAvailableSources returns possible Sources for the product and the desired delivery. // Optional the existing cart can be passed so that existing items in the cart can be evaluated also (e.g. deduct stock) // e.g. use this before a product should be placed in the cart to know if and from where an item can be sourced // throws ErrNeedMoreDetailsSourceCannotBeDetected // throws ErrNoSourceAvailable if no source is available for the product and the given delivery GetAvailableSources(ctx context.Context, product domain.BasicProduct, deliveryInfo *cartDomain.DeliveryInfo, decoratedCart *decorator.DecoratedCart) (AvailableSources, error) }
SourcingService describes the main port used by the sourcing logic.
type StockProvider ¶
type StockProvider interface {
GetStock(ctx context.Context, product domain.BasicProduct, source Source, deliveryInfo *cartDomain.DeliveryInfo) (int, error)
}
StockProvider interface for DefaultSourcingService