-
Notifications
You must be signed in to change notification settings - Fork 2
/
variant_price_model.go
70 lines (54 loc) · 1.48 KB
/
variant_price_model.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package model
import (
"regexp"
"strconv"
"strings"
)
// VPV: Variant Price Validation
type VPVCategory struct {
ID int `json:"id,string"`
}
type VPVInput struct {
Variant *Variant `json:"variant"`
Category *VPVCategory `json:"category"`
}
type VPVVariable struct {
Input *VPVInput `json:"input"`
}
type VPVProductValidateV3DataVariants struct {
Messages []string `json:"messages"`
Typename string `json:"__typename"`
}
var priceGrabRX = regexp.MustCompile(`[0-9]`)
func (v *VPVProductValidateV3DataVariants) GetPriceGab() int {
for _, message := range v.Messages {
if strings.Contains(message, "perbedaan harga") {
num := priceGrabRX.FindString(message)
fixnum, _ := strconv.Atoi(num)
return fixnum
}
}
return 0
}
type VPVProductValidateV3Data struct {
Variants *VPVProductValidateV3DataVariants `json:"variants"`
Typename string `json:"__typename"`
}
type VPVProductValidateV3 struct {
Header *Header `json:"header"`
IsSuccess bool `json:"isSuccess"`
Data *VPVProductValidateV3Data `json:"data"`
Typename string `json:"__typename"`
}
type VPVData struct {
ProductValidateV3 *VPVProductValidateV3 `json:"ProductValidateV3"`
}
type VPVRes struct {
Data VPVData `json:"data"`
}
func (r *VPVRes) GetPriceGab() int {
if r.Data.ProductValidateV3 != nil && r.Data.ProductValidateV3.Data != nil {
return r.Data.ProductValidateV3.Data.Variants.GetPriceGab()
}
return 0
}