Suyeon Jung

Add dong condition to result and Add input box to index

......@@ -6,6 +6,10 @@ require('dotenv').config();
/* GET home page. */
let SIGUN_CODE;
let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
let user_sigun;
let user_gu;
let user_dong;
let userLocation;
let user_latitude;
let user_logitude;
let sigun = [{
......@@ -142,8 +146,13 @@ let sigun = [{
// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
router.post('/', function(req, res) {
console.log(req.body);
let userLocation = req.body.userLocation;
console.log('사용자가 입력한 주소', userLocation);
user_sigun = req.body.sigun;
user_gu = req.body.gu;
user_dong = req.body.dong;
userLocation = `${user_sigun} ${user_gu} ${user_dong}`;
console.log(user_sigun);
console.log(user_gu);
console.log(user_dong);
let KAKAO_API_KEY = process.env.KAKAO_APIKEY;
let kakaoOptions = {
url: 'https://dapi.kakao.com/v2/local/search/address.json',
......@@ -174,49 +183,51 @@ router.post('/', function(req, res) {
console.log('위도, 경도', user_latitude, user_logitude);
}
})
res.render('category', { userLocation: req.body.userLocation });
res.render('category', { userLocation: userLocation });
});
router.get('/food', function(req, res) {
// 맛집 리스트 조회
let url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt';
let food_url = 'https://openapi.gg.go.kr/PlaceThatDoATasteyFoodSt';
let fastfood_url = 'https://openapi.gg.go.kr/Genrestrtfastfood'
let qs = `?KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}&Type=json`;
request({
url: url + qs,
url: food_url + qs,
method: 'GET'
}, function(err, response, body) {
if (!err && res.statusCode == 200) {
let food_result = JSON.parse(body);
// console.log('food_result', food_result.PlaceThatDoATasteyFoodSt[1]);
let store_names = [];
let stores = [];
for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) {
// 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR)
store_name = food_result.PlaceThatDoATasteyFoodSt[1].row[i];
console.log('store_name', store_name);
store_names.push(store_name);
store = food_result.PlaceThatDoATasteyFoodSt[1].row[i];
if (store['REFINE_LOTNO_ADDR'].includes(user_dong)) {
console.log('store', store);
stores.push(store);
}
}
console.log('food_result', food_result);
console.log('store_names', store_names);
console.log('stores', stores);
request({
url: fastfood_url + qs,
method: 'GET'
}, function(err, response, body) {
if (!err && res.statusCode == 200) {
let fast_food_result = JSON.parse(body);
let fast_store_names = [];
let fast_food_stores = [];
for (let i = 0; i < fast_food_result.Genrestrtfastfood[1].row.length; i++) {
fast_store_name = fast_food_result.Genrestrtfastfood[1].row[i];
fast_food_store = fast_food_result.Genrestrtfastfood[1].row[i];
// 폐업인 지점 제외
if (fast_store_name['BSN_STATE_NM'] != '폐업') {
console.log('fast_store_name', fast_store_name);
fast_store_names.push(fast_store_name);
if (fast_food_store['BSN_STATE_NM'] != '폐업' && fast_food_store['REFINE_LOTNO_ADDR'].includes(user_dong)) {
console.log('fast_store_name', fast_food_store);
fast_food_stores.push(fast_food_store);
}
}
res.render('food_result', { store_names: store_names, fast_store_names: fast_store_names });
res.render('food_result', { stores: stores, fast_food_stores: fast_food_stores });
}
})
......@@ -294,7 +305,7 @@ router.get('/park', function(req, res) {
});
router.get('/transport', function(req, res) {
res.send(BusCnt);
let
});
router.get('/safe', function(req, res) {
......
......@@ -8,24 +8,24 @@
<body>
<h1>🥘 맛집 현황 </h1>
<%for (var i =0; i <store_names.length; i++){%>
<%for (var i =0; i <stores.length; i++){%>
<li>
<%=store_names[i].RESTRT_NM%>
<%=stores[i].RESTRT_NM%>
</li>
<%}%>
<h3>총 맛집 개수 :
<%=store_names.length%>
<%=stores.length%>
</h3>
<h1>🍔 패스트푸드점 현황 </h1>
<%for (var i =0; i <fast_store_names.length; i++){%>
<%for (var i =0; i <fast_food_stores.length; i++){%>
<li>
<%=fast_store_names[i].BIZPLC_NM%>
<%=fast_food_stores[i].BIZPLC_NM%>
</li>
<%}%>
<h3>패스트푸드점 개수 :
<%=fast_store_names.length%>
<%=fast_food_stores.length%>
</h3>
</body>
......
......@@ -19,7 +19,9 @@
<input type="submit" id="search" value="검색"> -->
<div class="form-group">
<label for="exampleFormControlInput1">당신이 조사하고 싶은 동네의 주소를 입력하세요!</label>
<input type="text" class="form-control" id="exampleFormControlInput1" name="userLocation" placeholder="당신의 동네 주소를 입력해주세요(시/구/동)">
<input type="text" class="form-control" id="exampleFormControlInput1" name="sigun" placeholder="시/군을 입력하세요">
<input type="text" class="form-control" id="exampleFormControlInput1" name="gu" placeholder="구를 입력하세요">
<input type="text" class="form-control" id="exampleFormControlInput1" name="dong" placeholder="읍/면/동을 입력하세요">
</div>
<button type="submit" class="btn btn-primary">검색</button>
</form>
......