-
Notifications
You must be signed in to change notification settings - Fork 75
/
itemValidator.go
40 lines (31 loc) · 1 KB
/
itemValidator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package validation
import (
"context"
"fmt"
"flamingo.me/flamingo-commerce/v3/cart/domain/cart"
"flamingo.me/flamingo-commerce/v3/cart/domain/decorator"
"flamingo.me/flamingo/v3/framework/web"
"flamingo.me/flamingo-commerce/v3/product/domain"
)
//go:generate go run github.com/vektra/mockery/v2@v2.40.1 --name ItemValidator --case snake
type (
// ItemValidator checks a cart item
ItemValidator interface {
Validate(ctx context.Context, session *web.Session, cart *decorator.DecoratedCart, deliveryCode string, request cart.AddRequest, product domain.BasicProduct) error
}
// AddToCartNotAllowed error
AddToCartNotAllowed struct {
Reason string
RedirectHandlerName string
RedirectParams map[string]string
AdditionalData map[string]interface{}
}
)
// Error message
func (e *AddToCartNotAllowed) Error() string {
return fmt.Sprintf("Product is not allowed: %v", e.Reason)
}
// MessageCode message code
func (e *AddToCartNotAllowed) MessageCode() string {
return e.Reason
}