-
Notifications
You must be signed in to change notification settings - Fork 0
/
exchange.go
28 lines (24 loc) · 838 Bytes
/
exchange.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
package admin
import (
"github.com/qor/exchange"
"github.com/qor/qor"
"github.com/qor/qor-example/models/products"
"github.com/qor/qor/resource"
"github.com/qor/qor/utils"
"github.com/qor/validations"
)
// ProductExchange product exchange
var ProductExchange = exchange.NewResource(&products.Product{}, exchange.Config{PrimaryField: "Code"})
func init() {
ProductExchange.Meta(&exchange.Meta{Name: "Code"})
ProductExchange.Meta(&exchange.Meta{Name: "Name"})
ProductExchange.Meta(&exchange.Meta{Name: "Price"})
ProductExchange.AddValidator(&resource.Validator{
Handler: func(record interface{}, metaValues *resource.MetaValues, context *qor.Context) error {
if utils.ToInt(metaValues.Get("Price").Value) < 100 {
return validations.NewError(record, "Price", "price can't less than 100")
}
return nil
},
})
}