Documentation ¶
Index ¶
- Constants
- Variables
- type AllocatedQtys
- type AvailableSources
- type AvailableSourcesPerProduct
- 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, ...) (AvailableSourcesPerProduct, error)
- func (d *DefaultSourcingService) Inject(logger flamingo.Logger, dep ...) *DefaultSourcingService
- type ItemAllocation
- type ItemAllocations
- type ItemID
- type ProductID
- type Source
- type SourcingService
- type StockProvider
Constants ¶
const MaxSourceQty = math.MaxInt64
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 information are missing to determine a source ErrNeedMoreDetailsSourceCannotBeDetected = errors.New("source cannot be detected") // ErrUnsupportedProductType return when product type is not supported by the service ErrUnsupportedProductType = errors.New("unsupported product type") // ErrEmptyProductIdentifier return when product id is missing ErrEmptyProductIdentifier = errors.New("product identifier is empty") // ErrProductIsNil returned when nil product is received ErrProductIsNil = errors.New("received product in nil") // ErrStockProviderNotFound returned stock provider is nil ErrStockProviderNotFound = errors.New("no Stock Provider bound") // ErrSourceProviderNotFound returned source provider is nil ErrSourceProviderNotFound = errors.New("no Source Provider bound") // ErrCartNotProvided cart not provided ErrCartNotProvided = errors.New("cart not provided") )
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 AvailableSourcesPerProduct ¶ added in v3.7.0
type AvailableSourcesPerProduct map[ProductID]AvailableSources
func (AvailableSourcesPerProduct) FindSourcesWithLeastAvailableQty ¶ added in v3.7.0
func (as AvailableSourcesPerProduct) FindSourcesWithLeastAvailableQty() 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) (AvailableSourcesPerProduct, 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 map[ProductID]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) (AvailableSourcesPerProduct, 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