-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoppings.go
134 lines (120 loc) · 3.39 KB
/
toppings.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"DemaeDominos/dominos"
"encoding/xml"
"net/http"
)
/*
Since Domino's in house API is really only used in their apps, some stuff makes sense to them to be hardcoded.
Such things are the topping selections in the pizza and pasta categories. We will be hard coding the names of
the selection sections, but pull available toppings from the API.
*/
func getToppings(r *http.Request) ([]any, error) {
dom, err := dominos.NewDominos(r)
if err != nil {
return nil, err
}
toppingData, err := dom.GetToppings(r.URL.Query().Get("shopCode"), r.URL.Query().Get("itemCode"))
if err != nil {
return nil, err
}
sideData, err := dom.GetSides(r.URL.Query().Get("shopCode"), r.URL.Query().Get("itemCode"))
if err != nil {
return nil, err
}
var categories []ItemOne
if toppingData != nil {
categories = []ItemOne{
{
XMLName: xml.Name{Local: "container0"},
Info: CDATA{"Please choose a sauce."},
Code: CDATA{0},
Type: CDATA{"radio"},
Name: CDATA{"Sauce"},
List: KVFieldWChildren{
XMLName: xml.Name{Local: "list"},
},
},
{
XMLName: xml.Name{Local: "container1"},
Info: CDATA{"Please choose your meats. The * items are extra.\nNote you can only have 10 toppings."},
Code: CDATA{0},
Type: CDATA{1},
Name: CDATA{"Meats"},
List: KVFieldWChildren{
XMLName: xml.Name{Local: "list"},
},
},
{
XMLName: xml.Name{Local: "container2"},
Info: CDATA{"Please choose your non-meats. The * items are extra.\nNote you can only have 10 toppings."},
Code: CDATA{0},
Type: CDATA{1},
Name: CDATA{"Non-Meats"},
List: KVFieldWChildren{
XMLName: xml.Name{Local: "list"},
},
},
}
for _, topping := range toppingData {
currentSelection := &(categories[topping.Group])
currentSelection.List.Value = append(currentSelection.List.Value, Item{
MenuCode: CDATA{topping.Group},
ItemCode: CDATA{topping.Code},
Name: CDATA{topping.Name},
Price: CDATA{"--"},
Info: CDATA{""},
Size: nil,
Image: CDATA{"non"},
IsSoldout: CDATA{BoolToInt(false)},
SizeList: nil,
})
}
// Ensure toppings actually exist within the slice
categoryLength := len(categories)
for i := 0; i < categoryLength; i++ {
if len(categories[i].List.Value) == 0 {
categories = append(categories[:i], categories[i+1:]...)
i -= 1
categoryLength -= 1
}
}
}
if sideData != nil {
sidesStruct := ItemOne{
XMLName: xml.Name{Local: "container4"},
Info: CDATA{"Choose your sides. Note all sides are extra."},
Code: CDATA{0},
Type: CDATA{"1"},
Name: CDATA{"Sides"},
List: KVFieldWChildren{
XMLName: xml.Name{Local: "list"},
},
}
for _, side := range sideData {
sidesStruct.List.Value = append(sidesStruct.List.Value, Item{
MenuCode: CDATA{"side"},
ItemCode: CDATA{side.Code},
Name: CDATA{side.Name},
Price: CDATA{"--"},
Info: CDATA{""},
Size: nil,
Image: CDATA{"F_" + side.Code},
IsSoldout: CDATA{BoolToInt(false)},
SizeList: nil,
})
}
categories = append(categories, sidesStruct)
}
if sideData == nil && toppingData == nil {
// This item has no toppings
categories = append(categories, ItemOne{
Info: CDATA{},
Code: CDATA{},
Type: CDATA{},
Name: CDATA{},
List: KVFieldWChildren{},
})
}
return []any{categories[:]}, nil
}