Donghoon Kim

major bug fix #3

1 -const mysql = require('promise-mysql')
2 -
3 -module.exports = mysql.createConnection({
4 - host: "52.79.82.27",
5 - user: "root",
6 - password: "oss",
7 - database: "OSS"
8 -})
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
93 var result_food = [] 93 var result_food = []
94 var result_room = [] 94 var result_room = []
95 </script> 95 </script>
96 - <script type="text/javascript" src="/js/getPlaceList.js"></script> 96 + <script type="text/javascript" src="./js/getPlaceList.js"></script>
97 <div id="map"></div> 97 <div id="map"></div>
98 <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDg4CkUEEt_96n1ork1nL5t4E_SpdKrgMI&libraries=places&callback=initMap" async defer></script> 98 <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDg4CkUEEt_96n1ork1nL5t4E_SpdKrgMI&libraries=places&callback=initMap" async defer></script>
99 99
......
...@@ -19,12 +19,6 @@ function initMap() { ...@@ -19,12 +19,6 @@ function initMap() {
19 lng: position.coords.longitude 19 lng: position.coords.longitude
20 }; 20 };
21 21
22 - var map = new google.maps.Map(document.getElementById('map'), {
23 - center: pos,
24 - zoom: 17
25 - });
26 - infowindow = new google.maps.InfoWindow();
27 -
28 map.setCenter(pos); 22 map.setCenter(pos);
29 23
30 service = new google.maps.places.PlacesService(map); 24 service = new google.maps.places.PlacesService(map);
...@@ -44,20 +38,6 @@ function initMap() { ...@@ -44,20 +38,6 @@ function initMap() {
44 searchPlace('zoo','entertainment'); 38 searchPlace('zoo','entertainment');
45 39
46 searchPlace('lodging','room'); 40 searchPlace('lodging','room');
47 -
48 - // put data to db
49 - for (var i = 0; i < results_food.length; i++) {
50 - //putDataToDB(results_food[i], 'food')
51 - console.log(results_food[i])
52 - }
53 - for (var i = 0; i < results_entertainment.length; i++) {
54 - //putDataToDB(results_entertainment[i], 'entertainment')
55 - console.log(results_entertainment[i])
56 - }
57 - for (var i = 0; i < results_room.length; i++) {
58 - //putDataToDB(results_room[i], 'room')
59 - console.log(results_room[i])
60 - }
61 }); 41 });
62 } 42 }
63 } 43 }
...@@ -95,7 +75,6 @@ function searchPlace(str, placeType) { ...@@ -95,7 +75,6 @@ function searchPlace(str, placeType) {
95 function callback_foods(results, status) { 75 function callback_foods(results, status) {
96 if (status === google.maps.places.PlacesServiceStatus.OK) { 76 if (status === google.maps.places.PlacesServiceStatus.OK) {
97 for (var i = 0; i < results.length; i++) { 77 for (var i = 0; i < results.length; i++) {
98 - putDataToDB(results[i], 'food')
99 createMarker_foods(results[i]); 78 createMarker_foods(results[i]);
100 } 79 }
101 } 80 }
...@@ -104,7 +83,6 @@ function callback_foods(results, status) { ...@@ -104,7 +83,6 @@ function callback_foods(results, status) {
104 function callback_entertainment(results, status) { 83 function callback_entertainment(results, status) {
105 if (status === google.maps.places.PlacesServiceStatus.OK) { 84 if (status === google.maps.places.PlacesServiceStatus.OK) {
106 for (var i = 0; i < results.length; i++) { 85 for (var i = 0; i < results.length; i++) {
107 - putDataToDB(results[i], 'entertainment')
108 createMarker_entertainment(results[i]); 86 createMarker_entertainment(results[i]);
109 } 87 }
110 } 88 }
...@@ -113,7 +91,6 @@ function callback_entertainment(results, status) { ...@@ -113,7 +91,6 @@ function callback_entertainment(results, status) {
113 function callback_rooms(results, status) { 91 function callback_rooms(results, status) {
114 if (status === google.maps.places.PlacesServiceStatus.OK) { 92 if (status === google.maps.places.PlacesServiceStatus.OK) {
115 for (var i = 0; i < results.length; i++) { 93 for (var i = 0; i < results.length; i++) {
116 - putDataToDB(results[i], 'room')
117 createMarker_rooms(results[i]); 94 createMarker_rooms(results[i]);
118 } 95 }
119 } 96 }
...@@ -160,81 +137,3 @@ function createMarker_rooms(place) { ...@@ -160,81 +137,3 @@ function createMarker_rooms(place) {
160 infowindow.open(map, this); 137 infowindow.open(map, this);
161 }); 138 });
162 } 139 }
163 -
164 -function putDataToDB(result, category1) {
165 - const id = result['id'];
166 - const place_id =result['place_id'];
167 - const name = result['name'];
168 - const address = result['vicinity'];
169 - let category_big = category1
170 - const category_small = result.types[0];
171 - const image = "default"
172 - const rating = result.rating;
173 - const lng = result.geometry.viewport.ea.j;
174 - const lat =result.geometry.viewport.la.j;
175 -
176 - if(rating == null) {
177 - rating = 0;
178 - }
179 - const QueryCheck = () => {
180 - if (!id || !place_id || !name || !address || !category_big || !category_small || !image || !rating || !lng || !lat) {
181 - return Promise.reject({
182 - message: 'Query Error'
183 - })
184 - }
185 - return Promise.resolve()
186 - }
187 -
188 - // 2. SQL Start
189 - const SQLStart = async (pool) => {
190 - try {
191 - let data = await pool.query('INSERT INTO PLACE(ID, PLACE_ID, NAME, ADDRESS, CATEGORY_BIG, CATEGORY_SMALL, IMAGE, RATING, LNG, LAT) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);', [id, place_id, name, address, category_big, category_small, image, rating, lng, lat])
192 - return Promise.resolve(pool)
193 - } catch(err) {
194 - return Promise.reject(err)
195 - }
196 - }
197 - // 3. Response
198 - const Response = (rows) => {
199 - return res.status(200).json(rows)
200 - }
201 -
202 - // 1. Query Check
203 - const FindQueryCheck = () => {
204 - if (!id) {
205 - return Promise.reject({
206 - message: 'Query Error'
207 - })
208 - }
209 - else return pool
210 - }
211 -
212 - // 2. SQL Start
213 - const FindSQLStart = (pool) => {
214 - return pool.query('SELECT * FROM PLACE WHERE ID LIKE '+id.toString())
215 - }
216 -
217 - // 3. Response
218 - const FindResponse = (rows) => {
219 - return res.status(200).json(rows)
220 - }
221 -
222 - if([] == FindQueryCheck()
223 - .then(FindSQLStart)
224 - .then(FindResponse)
225 - .catch(err => {
226 - if (err) {
227 - return res.status(500).json(err.message || err)
228 - }
229 - }))
230 - {
231 - QueryCheck()
232 - .then(SQLStart)
233 - .then(Response)
234 - .catch(err => {
235 - if (err) {
236 - return res.status(500).json(err.message || err)
237 - }
238 - })
239 - }
240 -}
......
1 -var express = require('express');
2 -var router = express.Router();
3 -
4 -/* GET home page. */
5 -router.get('/', function(req, res, next) {
6 - res.render('index', { title: 'Express' });
7 -});
8 -
9 -module.exports = router;