Suyeon Jung

Add dong condition to all category

......@@ -142,6 +142,13 @@ let sigun = [{
},
]
let userArea = function(target, targetKey, user) {
if (target[targetKey].includes(user)) {
return true;
} else {
return false;
}
}
// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
router.post('/', function(req, res) {
......@@ -205,7 +212,7 @@ router.get('/food', function(req, res) {
for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) {
// 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR)
store = food_result.PlaceThatDoATasteyFoodSt[1].row[i];
if (store['REFINE_LOTNO_ADDR'].includes(user_dong)) {
if (userArea(store, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('store', store);
stores.push(store);
}
......@@ -222,7 +229,7 @@ router.get('/food', function(req, res) {
for (let i = 0; i < fast_food_result.Genrestrtfastfood[1].row.length; i++) {
fast_food_store = fast_food_result.Genrestrtfastfood[1].row[i];
// 폐업인 지점 제외
if (fast_food_store['BSN_STATE_NM'] != '폐업' && fast_food_store['REFINE_LOTNO_ADDR'].includes(user_dong)) {
if (fast_food_store['BSN_STATE_NM'] != '폐업' && userArea(fast_food_store, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('fast_store_name', fast_food_store);
fast_food_stores.push(fast_food_store);
}
......@@ -248,11 +255,14 @@ router.get('/school', function(req, res) {
if (!err && res.statusCode == 200) {
let library_result = JSON.parse(body);
console.log(library_result);
let library_names = [];
let librarys = [];
for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) {
library_name = library_result.Tbggibllbrm[1].row[i];
console.log('library_name', library_name);
library_names.push(library_name);
library = library_result.Tbggibllbrm[1].row[i];
if (userArea(library, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('library', library);
librarys.push(library);
}
}
request({
url: institute_url + qs,
......@@ -261,13 +271,15 @@ router.get('/school', function(req, res) {
if (!err && res.statusCode == 200) {
let institute_result = JSON.parse(body);
console.log(institute_result);
let institute_names = [];
let institutes = [];
for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) {
institute_name = institute_result.TninsttInstutM[1].row[i];
console.log('institute_name', institute_name);
institute_names.push(institute_name);
institute = institute_result.TninsttInstutM[1].row[i];
if (userArea(institute, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('institute', institute);
institutes.push(institute);
}
}
res.render('school_result', { library_names: library_names, institute_names: institute_names });
res.render('school_result', { librarys: librarys, institutes: institutes });
}
})
}
......@@ -286,12 +298,14 @@ router.get('/park', function(req, res) {
if (!err && res.statusCode == 200) {
let city_park_result = JSON.parse(body);
console.log('park', city_park_result)
let city_park_names = [];
let city_parks = [];
for (let i = 0; i < city_park_result.CityPark[1].row.length; i++) {
city_park_name = city_park_result.CityPark[1].row[i];
city_park_names.push(city_park_name);
city_park = city_park_result.CityPark[1].row[i];
if (userArea(city_park, 'REFINE_LOTNO_ADDR', user_dong)) {
city_parks.push(city_park);
}
}
res.render('park_result', { city_park_names: city_park_names });
res.render('park_result', { city_parks: city_parks });
}
// if (park_result.CityPark[0].head[1].RESULT.CODE == 'INFO-000') {
......@@ -322,8 +336,10 @@ router.get('/safe', function(req, res) {
console.log(cctv_result);
for (let i = 0; i < cctv_result.CCTV[1].row.length; i++) {
cctv = cctv_result.CCTV[1].row[i];
console.log('cctv', cctv);
cctvs.push(cctv);
if (userArea(cctv, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('cctv', cctv);
cctvs.push(cctv);
}
}
request({
url: light_url + qs,
......@@ -335,8 +351,10 @@ router.get('/safe', function(req, res) {
console.log(light_result);
for (let i = 0; i < light_result.SECRTLGT[1].row.length; i++) {
light = light_result.SECRTLGT[1].row[i];
console.log('light', light);
lights.push(light);
if (userArea(light, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('light', light);
lights.push(light);
}
}
res.render('safe_result', { cctvs: cctvs, lights: lights });
}
......@@ -361,7 +379,7 @@ router.get('/culture', function(req, res) {
for (let i = 0; i < sing_result.Songclub[1].row.length; i++) {
sing = sing_result.Songclub[1].row[i];
// 폐업인 지점 제외
if (!sing['BSN_STATE_NM'].includes('폐업')) {
if (!sing['BSN_STATE_NM'].includes('폐업') && userArea(sing, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('sing', sing);
sings.push(sing);
}
......@@ -386,24 +404,18 @@ router.get('/shop', function(req, res) {
for (let i = 0; i < shop_result.MrktStoreM[1].row.length; i++) {
shop = shop_result.MrktStoreM[1].row[i];
// 폐업인 지점 제외
console.log('shop', shop);
shops.push(shop);
if (userArea(shop, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('shop', shop);
shops.push(shop);
}
}
res.render('shop_result', { shops: shops });
}
// var shop_result = JSON.parse(body);
// if (shop_result.MrktStoreM[0].head[1].RESULT.CODE == 'INFO-000') {
// mallnum = shop_result.MrktStoreM[0].head[0].list_total_count;
// console.log(mallnum + "개의 쇼핑몰이 존재합니다.");
// res.send(String(mallnum) + "개의 쇼핑몰이 존재합니다.");
// } else {
// res.send("쇼핑몰이 없습니다.");
// }
})
});
router.get('/gym', function(req, res) {
let gymnum = 0;
let gym_url = 'https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace';
let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}`;
request({
......@@ -416,21 +428,14 @@ router.get('/gym', function(req, res) {
console.log(gym_result.PhysicaFitnessTrainingPlace[1]);
for (let i = 0; i < gym_result.PhysicaFitnessTrainingPlace[1].row.length; i++) {
gym = gym_result.PhysicaFitnessTrainingPlace[1].row[i];
console.log('gym', gym);
gyms.push(gym);
console.log(gym);
if (userArea(gym, 'REFINE_LOTNO_ADDR', user_dong)) {
console.log('gym', gym);
gyms.push(gym);
}
}
res.render('gym_result', { gyms: gyms });
}
// if (gym_result.PhysicaFitnessTrainingPlace[0].head[1].RESULT.CODE == 'INFO-000') {
// gymnum = gym_result.PhysicaFitnessTrainingPlace[0].head[0].list_total_count;
// console.log(gymnum + "개의 체육관이 존재합니다.");
// res.send(String(gymnum) + "개의 체육관이 존재합니다.");
// } else {
// console.log("주변에 체육관이 없습니다.");
// res.send("주변에 체육관이 없습니다.");
// }
})
});
......
......@@ -8,14 +8,14 @@
<body>
<h1>🌳 도시공원 현황 </h1>
<%for (var i =0; i <city_park_names.length; i++){%>
<%for (var i =0; i <city_parks.length; i++){%>
<li>
<%=city_park_names[i].PARK_NM%>
<%=city_parks[i].PARK_NM%>
</li>
<%}%>
<h3>총 도시공원 개수 :
<%=city_park_names.length%>
<%=city_parks.length%>
</h3>
</body>
......
......@@ -8,24 +8,24 @@
<body>
<h1>📚 도서관 현황 </h1>
<%for (var i =0; i <library_names.length; i++){%>
<%for (var i =0; i <librarys.length; i++){%>
<li>
<%=library_names[i].LIBRRY_NM%>
<%=librarys[i].LIBRRY_NM%>
</li>
<%}%>
<h3>총 도서관 개수 :
<%=library_names.length%>
<%=librarys.length%>
</h3>
<h1>📒 학원 현황 </h1>
<%for (var i =0; i <institute_names.length; i++){%>
<%for (var i =0; i <institutes.length; i++){%>
<li>
<%=institute_names[i].FACLT_NM%>
<%=institutes[i].FACLT_NM%>
</li>
<%}%>
<h3>학원 및 교습소 개수 :
<%=institute_names.length%>
<%=institutes.length%>
</h3>
</body>
......