validation

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddToCartNotAllowed

type AddToCartNotAllowed struct {
	Reason              string
	RedirectHandlerName string
	RedirectParams      map[string]string
	AdditionalData      map[string]interface{}
}

AddToCartNotAllowed error

func (*AddToCartNotAllowed) Error

func (e *AddToCartNotAllowed) Error() string

Error message

func (*AddToCartNotAllowed) MessageCode

func (e *AddToCartNotAllowed) MessageCode() string

MessageCode message code

type ItemValidationError

type ItemValidationError struct {
	ItemID          string
	ErrorMessageKey string
}

ItemValidationError applies for a single item

type ItemValidator

type ItemValidator interface {
	Validate(ctx context.Context, session *web.Session, cart *decorator.DecoratedCart, deliveryCode string, request cart.AddRequest, product domain.BasicProduct) error
}

ItemValidator checks a cart item

type MaxQuantityRestrictor

type MaxQuantityRestrictor interface {
	// Name returns the code of the restrictor
	Name() string
	// Restrict must return a `RestrictionResult` which contains information regarding if a restriction is
	// applied and whats the max allowed quantity. Might expect item id from context in implementation.
	Restrict(ctx context.Context, session *web.Session, product domain.BasicProduct, cart *cart.Cart, deliveryCode string) *RestrictionResult
}

MaxQuantityRestrictor returns the maximum qty allowed for a given product and cart it is possible to register many (MultiBind) MaxQuantityRestrictor implementations

type PaymentSelectionValidator

type PaymentSelectionValidator interface {
	Validate(ctx context.Context, cart *decorator.DecoratedCart, selection cart.PaymentSelection) error
}

PaymentSelectionValidator decides if the PaymentSelection is valid

type RestrictionResult

type RestrictionResult struct {
	IsRestricted        bool
	MaxAllowed          int
	RemainingDifference int
	RestrictorName      string
}

RestrictionResult contains the result of a restriction

type RestrictionService

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

RestrictionService checks product restriction

func (*RestrictionService) Inject

func (rs *RestrictionService) Inject(
	qtyRestrictors []MaxQuantityRestrictor,
) *RestrictionService

Inject dependencies

func (*RestrictionService) RestrictQty

func (rs *RestrictionService) RestrictQty(ctx context.Context, session *web.Session, product domain.BasicProduct, currentCart *cart.Cart, deliveryCode string) *RestrictionResult

RestrictQty checks if there is an qty restriction present and returns an according result containing the max allowed quantity and the quantity difference to the current cart. Restrictor might expect item id in context

type Result

type Result struct {
	HasCommonError        bool
	CommonErrorMessageKey string
	ItemResults           []ItemValidationError
}

Result groups the validation result

func (Result) GetErrorMessageKeyForItem

func (c Result) GetErrorMessageKeyForItem(id string) string

GetErrorMessageKeyForItem returns the specific error message for that item

func (Result) HasErrorForItem

func (c Result) HasErrorForItem(id string) bool

HasErrorForItem checks if a specified item has an error

func (Result) IsValid

func (c Result) IsValid() bool

IsValid is valid is true if no errors occurred

type Validator

type Validator interface {
	Validate(ctx context.Context, session *web.Session, cart *decorator.DecoratedCart) Result
}

Validator checks a complete decorated cart

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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