Suyeon Jung

Complete gym category

...@@ -326,26 +326,34 @@ router.get('/shop', function(req, res) { ...@@ -326,26 +326,34 @@ router.get('/shop', function(req, res) {
326 }); 326 });
327 327
328 router.get('/gym', function(req, res) { 328 router.get('/gym', function(req, res) {
329 - let GYEONGI_API_KEY = process.env.GYEONGGI_APIKEY;
330 - let sigun_cd = SIGUN_CODE;
331 let gymnum = 0; 329 let gymnum = 0;
332 - let url = 'https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace'; 330 + let gym_url = 'https://openapi.gg.go.kr/PhysicaFitnessTrainingPlace';
333 - let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${sigun_cd}`; 331 + let qs = `?Type=json&KEY=${GYEONGI_API_KEY}&SIGUN_CD=${SIGUN_CODE}`;
334 request({ 332 request({
335 - url: url + qs, 333 + url: gym_url + qs,
336 method: 'GET' 334 method: 'GET'
337 }, function(err, response, body) { 335 }, function(err, response, body) {
338 - var gym_result = JSON.parse(body); 336 + if (!err && res.statusCode == 200) {
339 - if (gym_result.PhysicaFitnessTrainingPlace[0].head[1].RESULT.CODE == 'INFO-000') { 337 + let gym_result = JSON.parse(body);
338 + let gyms = [];
339 + console.log(gym_result.PhysicaFitnessTrainingPlace[1]);
340 + for (let i = 0; i < gym_result.PhysicaFitnessTrainingPlace[1].row.length; i++) {
341 + gym = gym_result.PhysicaFitnessTrainingPlace[1].row[i];
342 + console.log('gym', gym);
343 + gyms.push(gym);
344 + }
345 + res.render('gym_result', { gyms: gyms });
346 + }
347 + // if (gym_result.PhysicaFitnessTrainingPlace[0].head[1].RESULT.CODE == 'INFO-000') {
340 348
341 - gymnum = gym_result.PhysicaFitnessTrainingPlace[0].head[0].list_total_count; 349 + // gymnum = gym_result.PhysicaFitnessTrainingPlace[0].head[0].list_total_count;
342 - console.log(gymnum + "개의 체육관이 존재합니다."); 350 + // console.log(gymnum + "개의 체육관이 존재합니다.");
343 - res.send(String(gymnum) + "개의 체육관이 존재합니다."); 351 + // res.send(String(gymnum) + "개의 체육관이 존재합니다.");
344 - } else { 352 + // } else {
345 353
346 - console.log("주변에 체육관이 없습니다."); 354 + // console.log("주변에 체육관이 없습니다.");
347 - res.send("주변에 체육관이 없습니다."); 355 + // res.send("주변에 체육관이 없습니다.");
348 - } 356 + // }
349 }) 357 })
350 }); 358 });
351 router.get('/transport', function(req, res) { 359 router.get('/transport', function(req, res) {
......
1 +<!DOCTYPE html>
2 +<html lang="ko">
3 +
4 +<head>
5 + <meta charset="UTF-8">
6 + <title>✍️ 결과 페이지</title>
7 +</head>
8 +
9 +<body>
10 + <h1>🏋️‍♂️ 운동시설 현황 </h1>
11 + <%for (var i =0; i <gyms.length; i++){%>
12 + <li>
13 + <%=gyms[i].BIZPLC_NM%>
14 + </li>
15 +
16 + <%}%>
17 + <h3>총 운동시설 개수 :
18 + <%=gyms.length%>
19 + </h3>
20 +
21 +</body>
22 +
23 +</html>
...\ No newline at end of file ...\ No newline at end of file