all the refactor
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"git.k6n.net/mats/platform/money"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -74,7 +76,7 @@ const (
|
||||
type ruleCondition struct {
|
||||
Kind RuleKind
|
||||
StringVals []string // For sku / category multi-value list
|
||||
MinValue *int64 // For numeric threshold rules
|
||||
MinValue *money.Cents // For numeric threshold rules (minor units)
|
||||
// Operator reserved for future (e.g., >, >=, ==). Currently always ">=" for numeric kinds.
|
||||
Operator string
|
||||
}
|
||||
@@ -90,13 +92,13 @@ type RuleSet struct {
|
||||
type Item struct {
|
||||
Sku string
|
||||
Category string
|
||||
UnitPrice int64 // Inc VAT (single unit)
|
||||
UnitPrice money.Cents // Inc VAT (single unit)
|
||||
}
|
||||
|
||||
// EvalContext bundles cart-like data necessary for evaluation.
|
||||
type EvalContext struct {
|
||||
Items []Item
|
||||
CartTotalInc int64
|
||||
CartTotalInc money.Cents
|
||||
}
|
||||
|
||||
// Applies returns true if all rule conditions pass for the context.
|
||||
@@ -268,9 +270,10 @@ func parseNumericRule(frag string) (ruleCondition, error) {
|
||||
return ruleCondition{}, fmt.Errorf("negative threshold %d", value)
|
||||
}
|
||||
|
||||
mv := money.Cents(value)
|
||||
return ruleCondition{
|
||||
Kind: kind,
|
||||
MinValue: &value,
|
||||
MinValue: &mv,
|
||||
Operator: ">=",
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user