-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
151 lines (133 loc) · 4.53 KB
/
main.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
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"github.com/gin-gonic/gin"
)
var db = make(map[string]string)
type TenBisRes struct {
Errors []string `json:"Errors"`
Success bool `json:"Success"`
Data Data `json:"Data"`
}
type Data struct {
RestaurantsList []Restaurant `json:"restaurantsList`
CategoriesList []Category `json:"categoriesList`
}
type Restaurant struct {
Id int32 `json:"restaurantId"`
Name string `json:"restaurantName"`
Address string `json:"restaurantAddress"`
CityName string `json:"restaurantCityName"`
}
type Category struct {
Id int32 `json:"categoryId"`
Desc string `json:"categoryDesc"`
Name string `json:"categoryName"`
DishList []Dish `json:"dishList"`
}
type Dish struct {
Id int32 `json:"dishId"`
Price int32 `json:"dishPrice"`
Description string `json:"dishDescription"`
Name string `json:"dishName"`
ImageUrl string `json:"dishImageUrl"`
DishList []Dish `json:"dishList"`
}
type Login struct {
Model LoginModel `json:"model"`
ReturnURL string `json:"returnUrl"`
}
type LoginModel struct {
UserName string `json:"UserName`
Password string `json:"Password`
}
var host = "https://www.10bis.co.il/"
var api = "NextApi/"
var search = "SearchRestaurants"
var menu = "GetRestaurantMenu"
var login = "Account/LogOnAjax"
func setupRouter() *gin.Engine {
// Disable Console Color
// gin.DisableConsoleColor()
r := gin.Default()
r.GET("/getRestaurants", func(c *gin.Context) {
url := host + api + search + "?addressId=3525498&cityId=24&cityName=%D7%AA%D7%9C+%D7%90%D7%91%D7%99%D7%91+%D7%99%D7%A4%D7%95&streetId=23322&streetName=%D7%93%D7%A8%D7%9A+%D7%9E%D7%A0%D7%97%D7%9D+%D7%91%D7%92%D7%99%D7%9F&houseNumber=52&entrance=%D7%91%D7%A0%D7%99%D7%99%D7%9F+%D7%A1%D7%95%D7%A0%D7%95%D7%9C&floor=13&longitude=34.7814426&latitude=32.0637232&phone01=0&isCompanyAddress=true&addressCompanyId=5969&addressKey=24-23322-52-3525498&deliveryMethod=Delivery&enableNewResAndCouponsPromotion=true"
resp, err := http.Get(url)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
c.Header("Content-Type", "application/json")
var objmap TenBisRes
err = json.Unmarshal(body, &objmap)
restList, err := json.Marshal(objmap.Data.RestaurantsList)
// fmt.Println(string(restList))
if err != nil && restList == nil {
fmt.Println(err)
}
c.Data(http.StatusOK, "application/json", restList)
})
r.GET("/getDishes", func(c *gin.Context) {
restId := c.Request.URL.Query()["restaurantId"][0]
url := host + api + menu + "?restaurantId=" + restId + "&deliveryMethod=Delivery"
resp, err := http.Get(url)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
c.Header("Content-Type", "application/json")
var objmap TenBisRes
err = json.Unmarshal(body, &objmap)
restList, err := json.Marshal(objmap.Data.CategoriesList)
// fmt.Println(string(restList))
if err != nil && restList == nil {
fmt.Println(err)
}
c.Data(http.StatusOK, "application/json", restList)
})
r.POST("/wut", func(c *gin.Context) {
restId := c.Request.URL.Query()["restaurantId"][0]
url := host + api + menu + "?restaurantId=" + restId + "&deliveryMethod=Delivery"
resp, err := http.Get(url)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
c.Header("Content-Type", "application/json")
var objmap TenBisRes
err = json.Unmarshal(body, &objmap)
restList, err := json.Marshal(objmap.Data.CategoriesList)
// fmt.Println(string(restList))
if err != nil && restList == nil {
fmt.Println(err)
}
c.Data(http.StatusOK, "application/json", restList)
})
r.GET("/login", func(c *gin.Context) {
userName := c.Request.URL.Query()["userName"][0]
password := c.Request.URL.Query()["password"][0]
wut := []byte(`{"model": {"UserName":"` + userName + `", "Password":"` + password + `"}}`)
url := host + login
resp, err := http.Post(url, "application/json", bytes.NewBuffer(wut))
fmt.Println("gothere")
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
// c.Header("Content-Type", "application/json")
// var objmap TenBisRes
// err = json.Unmarshal(body, &objmap)
// restList, err := json.Marshal(objmap.Data.CategoriesList)
// fmt.Println(string(restList))
if err != nil {
fmt.Println(body, wut)
}
uid := resp.Cookies()[1].Value
tenbisCtx := resp.Cookies()[4].Value
fmt.Println(uid)
fmt.Println(tenbisCtx)
c.Data(http.StatusOK, "application/json", []byte(tenbisCtx))
})
return r
}
func main() {
r := setupRouter()
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
}