price

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 8 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMismatchingUnit when the unit of the 2 prices do not match when using Add
	ErrMismatchingUnit = errors.New("the unit is not the same")

	// ErrMismatchingCurrency when the currency of the 2 prices do not match when using Add
	ErrMismatchingCurrency = errors.New("the currency is not the same")
)

Functions

This section is empty.

Types

type AttributeFilter

type AttributeFilter struct {
	Key        string
	Value      *string
	ValueRegex *string
}

AttributeFilter is used for filtering of prices by attribute.

type Filter

type Filter struct {
	Unit             *string
	Currency         *string
	AttributeFilters []*AttributeFilter
}

Filter is used to filter prices.

type ID

type ID uint32

ID represents the Price ID.

type Price

type Price struct {
	ID         ID
	Unit       string
	Currency   string
	Value      decimal.Decimal
	Attributes map[string]string
}

Price is a single pricing entry for a product.

func (*Price) Add added in v0.5.0

func (p *Price) Add(pr Price) error

Add checks that the 2 prices can be added together (unit/currency) and then performs an addition and also joins the attributes and replacing repeated ones for the new ones (pr)

func (*Price) GenerateHash

func (p *Price) GenerateHash() string

GenerateHash generates the Hash field of the Price, equal to the MD5 sum of its unique values.

type Repository

type Repository interface {
	// Filter returns Prices with attributes matching the product.ID and Filter.
	Filter(ctx context.Context, productID product.ID, filter *Filter) ([]*Price, error)

	// Upsert updates a Price or creates a new one if it doesn't already exist.
	Upsert(ctx context.Context, p *WithProduct) (ID, error)

	// DeleteByProductWithKeep deletes all Prices of the specified product.ID except the ones with ID in the keep slice.
	DeleteByProductWithKeep(ctx context.Context, productID product.ID, keep []ID) error
}

Repository describes interactions with a storage system to deal with Price entries.

type WithProduct

type WithProduct struct {
	Price
	Product *product.Product
}

WithProduct is an aggregation of a Price with a product.Product.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL