-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.go
141 lines (120 loc) · 2.9 KB
/
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
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
135
136
137
138
package main
//CATEGORY DEFINITION
type Category int
const(
Technology Category = iota
Accessory
Clothes
)
type Categories map[Category]string
func(c Categories) Init(){
c[Technology] = "Technology"
c[Accessory] = "Accessory"
c[Clothes] = "Clothes"
}
var categories = Categories{}
// PRODUCT DEFINITION
type Product struct {
ProductId int `json:"product_id"`
ProductImageSource string `json:"product_image_source"`
ProductName string `json:"product_name"`
ProductPrice string `json:"product_price"`
ProductCategory string `json:"product_category"`
ProductColor string `json:"product_color"`
}
type Products map[int]Product
func(p Products) Init(){
if categories == nil {
categories.Init()
}
p[0] = Product{
ProductId: 0,
ProductColor:"Gray",
ProductName: "ASUS MG- Laptop",
ProductPrice: "10500",
ProductCategory: categories[Technology],
ProductImageSource: "img/asus.jpeg",
}
p[1] = Product{
ProductId: 1,
ProductColor:"Turquoise",
ProductName: "iPhone 11",
ProductPrice: "10500",
ProductCategory: categories[Technology],
ProductImageSource: "img/iphone.jpeg",
}
p[2] = Product{
ProductId: 2,
ProductColor:"Beige",
ProductName: "Smart Bag",
ProductPrice: "500",
ProductCategory: categories[Accessory],
ProductImageSource: "img/iphone.jpeg",
}
p[3] = Product{
ProductId: 3,
ProductColor:"Black",
ProductName: "Sony LCD-TV",
ProductPrice: "15000",
ProductCategory: categories[Technology],
ProductImageSource: "img/sony.jpeg",
}
p[4] = Product{
ProductId: 4,
ProductColor:"Black",
ProductName: "T-Shirt",
ProductPrice: "50",
ProductCategory: categories[Clothes],
ProductImageSource: "img/tshirt.jpeg",
}
}
func (p Products) TransformToSlice() []Product{
var productSlice = []Product{}
for _, product := range p {
productSlice = append(productSlice,product)
}
return productSlice
}
func(p Products) Clear(){
//p = map[int]Product{}
for k := range p {
delete(p, k)
}
}
var products = Products{}
// BASKET DEFINITION
type BasketProduct struct{
Product Product `json:"product"`
Count int `json:"count"`
}
type BasketProducts map[int]BasketProduct
func(bp BasketProducts) Clear(){
//p = map[int]Product{}
for k := range bp {
delete(bp, k)
}
}
func(bp BasketProducts) Copy() map[int]BasketProduct {
var copiedBasketProduct = BasketProducts{}
for index, element := range bp {
copiedBasketProduct[index] = element
}
return copiedBasketProduct
}
func(bp BasketProducts) TransformToSlice() []BasketProduct{
var basketProductSlice = []BasketProduct{}
for _,basketProduct := range bp {
basketProductSlice = append(basketProductSlice,basketProduct)
}
return basketProductSlice
}
var basketProducts = BasketProducts{}
type BasketCount struct {
Value int `json:"count"`
}
var basketCount = BasketCount{}
func InitializeModels(){
categories.Init()
products.Init()
basketCount.Value = 0
}