Showing
10 changed files
with
103 additions
and
62 deletions
api/Foods.js
deleted
100644 → 0
File mode changed
1 | -var map; | ||
2 | var pos; | 1 | var pos; |
3 | var infowindow; | 2 | var infowindow; |
4 | var service; | 3 | var service; |
5 | -var result_food = []; | ||
6 | -var result_entertainment = []; | ||
7 | -var result_room = []; | ||
8 | 4 | ||
9 | -export { pos as posiiton }; | 5 | +var result_entertainment = [] |
10 | -export { result_food as foodList }; | 6 | +var result_food = [] |
11 | -export { result_entertainment as entList }; | 7 | +var result_room = [] |
12 | -export { result_room as roomList }; | ||
13 | 8 | ||
14 | function initMap() { | 9 | function initMap() { |
15 | - map = new google.maps.Map(document.getElementById('map'), { | ||
16 | - center: {lat: -34.397, lng: 150.644}, | ||
17 | - zoom: 17 | ||
18 | - }); | ||
19 | - infowindow = new google.maps.InfoWindow(); | ||
20 | - | ||
21 | - | ||
22 | // Try HTML5 geolocation. | 10 | // Try HTML5 geolocation. |
23 | if (navigator.geolocation) { | 11 | if (navigator.geolocation) { |
24 | navigator.geolocation.getCurrentPosition(function(position) { | 12 | navigator.geolocation.getCurrentPosition(function(position) { |
... | @@ -27,22 +15,22 @@ function initMap() { | ... | @@ -27,22 +15,22 @@ function initMap() { |
27 | lng: position.coords.longitude | 15 | lng: position.coords.longitude |
28 | }; | 16 | }; |
29 | 17 | ||
18 | + var map = new google.maps.Map(document.getElementById('map'), { | ||
19 | + center: pos, | ||
20 | + zoom: 17 | ||
21 | + }); | ||
22 | + infowindow = new google.maps.InfoWindow(); | ||
23 | + | ||
30 | map.setCenter(pos); | 24 | map.setCenter(pos); |
31 | 25 | ||
32 | service = new google.maps.places.PlacesService(map); | 26 | service = new google.maps.places.PlacesService(map); |
33 | 27 | ||
34 | - service.nearbySearch({ | ||
35 | - location: pos, | ||
36 | - radius: 500, | ||
37 | - type: ['bakery'] | ||
38 | - }, callback_foods); | ||
39 | - | ||
40 | searchPlace('bar','food'); | 28 | searchPlace('bar','food'); |
41 | searchPlace('cafe','food'); | 29 | searchPlace('cafe','food'); |
42 | searchPlace('meal_delivery','food'); | 30 | searchPlace('meal_delivery','food'); |
43 | searchPlace('meal_takeaway','food'); | 31 | searchPlace('meal_takeaway','food'); |
44 | searchPlace('restaurant','food'); | 32 | searchPlace('restaurant','food'); |
45 | - | 33 | + searchPlace('bakery','food'); |
46 | 34 | ||
47 | searchPlace('department_store','entertainment'); | 35 | searchPlace('department_store','entertainment'); |
48 | searchPlace('movie_theater','entertainment'); | 36 | searchPlace('movie_theater','entertainment'); |
... | @@ -52,6 +40,17 @@ function initMap() { | ... | @@ -52,6 +40,17 @@ function initMap() { |
52 | searchPlace('zoo','entertainment'); | 40 | searchPlace('zoo','entertainment'); |
53 | 41 | ||
54 | searchPlace('lodging','room'); | 42 | searchPlace('lodging','room'); |
43 | + | ||
44 | + // put data to db | ||
45 | + for (var i = 0; i < results_food.length; i++) { | ||
46 | + putDataToDB(results_food[i], 'food') | ||
47 | + } | ||
48 | + for (var i = 0; i < results_entertainment.length; i++) { | ||
49 | + putDataToDB(results_entertainment[i], 'entertainment') | ||
50 | + } | ||
51 | + for (var i = 0; i < results_room.length; i++) { | ||
52 | + putDataToDB(results_room[i], 'room') | ||
53 | + } | ||
55 | }); | 54 | }); |
56 | } | 55 | } |
57 | } | 56 | } |
... | @@ -62,21 +61,21 @@ function searchPlace(str, placeType) { | ... | @@ -62,21 +61,21 @@ function searchPlace(str, placeType) { |
62 | service.nearbySearch({ | 61 | service.nearbySearch({ |
63 | location: pos, | 62 | location: pos, |
64 | radius: 500, | 63 | radius: 500, |
65 | - type: ['meal_takeaway'] | 64 | + type: [str] |
66 | }, callback_foods); | 65 | }, callback_foods); |
67 | break; | 66 | break; |
68 | case 'entertainment': | 67 | case 'entertainment': |
69 | service.nearbySearch({ | 68 | service.nearbySearch({ |
70 | location: pos, | 69 | location: pos, |
71 | radius: 500, | 70 | radius: 500, |
72 | - type: [str.toString()] | 71 | + type: [str] |
73 | }, callback_entertainment); | 72 | }, callback_entertainment); |
74 | break; | 73 | break; |
75 | case 'room': | 74 | case 'room': |
76 | service.nearbySearch({ | 75 | service.nearbySearch({ |
77 | location: pos, | 76 | location: pos, |
78 | radius: 500, | 77 | radius: 500, |
79 | - type: ['lodging'] | 78 | + type: [str] |
80 | }, callback_rooms); | 79 | }, callback_rooms); |
81 | break; | 80 | break; |
82 | default: | 81 | default: |
... | @@ -112,8 +111,6 @@ function callback_rooms(results, status) { | ... | @@ -112,8 +111,6 @@ function callback_rooms(results, status) { |
112 | } | 111 | } |
113 | } | 112 | } |
114 | 113 | ||
115 | - | ||
116 | - | ||
117 | function createMarker_foods(place) { | 114 | function createMarker_foods(place) { |
118 | var marker = new google.maps.Marker({ | 115 | var marker = new google.maps.Marker({ |
119 | map: map, | 116 | map: map, |
... | @@ -155,3 +152,78 @@ function createMarker_rooms(place) { | ... | @@ -155,3 +152,78 @@ function createMarker_rooms(place) { |
155 | infowindow.open(map, this); | 152 | infowindow.open(map, this); |
156 | }); | 153 | }); |
157 | } | 154 | } |
155 | + | ||
156 | +function putDataToDB(result, category1) { | ||
157 | + const id = result; | ||
158 | + const place_id =result; | ||
159 | + const name = result; | ||
160 | + const address = result; | ||
161 | + let category_big = category1 | ||
162 | + const category_small = result; | ||
163 | + const image = result; | ||
164 | + const rating = result; | ||
165 | + const lng = result; | ||
166 | + const lat =result; | ||
167 | + | ||
168 | + const QueryCheck = () => { | ||
169 | + if (!id || !place_id || !name || !address || !category_big || !category_small || !image || !rating || !lng || !lat) { | ||
170 | + return Promise.reject({ | ||
171 | + message: 'Query Error' | ||
172 | + }) | ||
173 | + } | ||
174 | + return Promise.resolve() | ||
175 | + } | ||
176 | + | ||
177 | + // 2. SQL Start | ||
178 | + const SQLStart = async (pool) => { | ||
179 | + try { | ||
180 | + 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]) | ||
181 | + return Promise.resolve(pool) | ||
182 | + } catch(err) { | ||
183 | + return Promise.reject(err) | ||
184 | + } | ||
185 | + } | ||
186 | + // 3. Response | ||
187 | + const Response = (rows) => { | ||
188 | + return res.status(200).json(rows) | ||
189 | + } | ||
190 | + | ||
191 | + // 1. Query Check | ||
192 | + const FindQueryCheck = () => { | ||
193 | + if (!keyword) { | ||
194 | + return Promise.reject({ | ||
195 | + message: 'Query Error' | ||
196 | + }) | ||
197 | + } | ||
198 | + else return pool | ||
199 | + } | ||
200 | + | ||
201 | + // 2. SQL Start | ||
202 | + const FindSQLStart = (pool) => { | ||
203 | + return pool.query(`SELECT * FROM PLACE WHERE ID LIKE '%${id}%') | ||
204 | + } | ||
205 | + | ||
206 | + // 3. Response | ||
207 | + const FindResponse = (rows) => { | ||
208 | + return res.status(200).json(rows) | ||
209 | + } | ||
210 | + | ||
211 | + if([] == FindQueryCheck() | ||
212 | + .then(FindSQLStart) | ||
213 | + .then(FindResponse) | ||
214 | + .catch(err => { | ||
215 | + if (err) { | ||
216 | + return res.status(500).json(err.message || err) | ||
217 | + } | ||
218 | + })) | ||
219 | + { | ||
220 | + QueryCheck() | ||
221 | + .then(SQLStart) | ||
222 | + .then(Response) | ||
223 | + .catch(err => { | ||
224 | + if (err) { | ||
225 | + return res.status(500).json(err.message || err) | ||
226 | + } | ||
227 | + }) | ||
228 | + } | ||
229 | +} | ... | ... |
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | -var path = require('path'); | 2 | +var router = require('./routes'); |
3 | -var cookieParser = require('cookie-parser'); | ||
4 | -var logger = require('morgan'); | ||
5 | - | ||
6 | -var indexRouter = require('./routes/index'); | ||
7 | -var usersRouter = require('./routes/users'); | ||
8 | - | ||
9 | var app = express(); | 3 | var app = express(); |
10 | 4 | ||
11 | -app.use(logger('dev')); | 5 | +app.use('/', router); |
12 | -app.use(express.json()); | ||
13 | -app.use(express.urlencoded({ extended: false })); | ||
14 | -app.use(cookieParser()); | ||
15 | -app.use(express.static(path.join(__dirname, 'public'))); | ||
16 | - | ||
17 | -app.use('/', indexRouter); | ||
18 | -app.use('/users', usersRouter); | ||
19 | 6 | ||
20 | var server = app.listen(3000); | 7 | var server = app.listen(3000); | ... | ... |
main.js
deleted
100644 → 0
1 | -console.log("Hello World!"); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -95,7 +95,7 @@ | ... | @@ -95,7 +95,7 @@ |
95 | </ul> | 95 | </ul> |
96 | 96 | ||
97 | <div id="content-wrapper"> | 97 | <div id="content-wrapper"> |
98 | - <script type="text/javascript" src="js/getPlaceList.js"></script> | 98 | + <script type="text/javascript" src="/../api/getPlaceList.js"></script> |
99 | <div id="map"></div> | 99 | <div id="map"></div> |
100 | <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDg4CkUEEt_96n1ork1nL5t4E_SpdKrgMI&libraries=places&callback=initMap" async defer></script> | 100 | <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDg4CkUEEt_96n1ork1nL5t4E_SpdKrgMI&libraries=places&callback=initMap" async defer></script> |
101 | <!-- Sticky Footer --> | 101 | <!-- Sticky Footer --> | ... | ... |
public/js/showEnt.js
deleted
100644 → 0
1 | -import entList from 'getPlaceList' |
public/js/showFood.js
deleted
100644 → 0
public/js/showRoom.js
deleted
100644 → 0
1 | -import roomList from 'getPlaceList' |
... | @@ -6,8 +6,4 @@ router.get('/', function(req, res, next) { | ... | @@ -6,8 +6,4 @@ router.get('/', function(req, res, next) { |
6 | res.render('index', { title: 'Express' }); | 6 | res.render('index', { title: 'Express' }); |
7 | }); | 7 | }); |
8 | 8 | ||
9 | -router.get('/Foods', function(req, res, next) { | ||
10 | - res.render('Foods', { title: 'Express' }); | ||
11 | -}); | ||
12 | - | ||
13 | -module.exports = router; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
9 | +module.exports = router; | ... | ... |
-
Please register or login to post a comment