Eunsu486

Modifyinf files

...@@ -10,57 +10,7 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY; ...@@ -10,57 +10,7 @@ let ANIMAL_INFO_API_KEY = process.env.REACT_APP_API_KEY;
10 let gu_select; 10 let gu_select;
11 11
12 12
13 -//동물병원 13 +// 사용자가 index 페이지에서 주소선택. 입력값받아오는 함수
14 -// router.post('/hospital', function (req, res) {
15 -// //gu 받아오기
16 -// var body = req.body;
17 -// var gu_select = body.user_gu;
18 -// var menu = '동물병원';
19 -// // encoding for url
20 -// var menu_encode = urlencode(menu);
21 -// var gu_select_encode = urlencode(gu_select);
22 -// //api
23 -// let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=200&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`;
24 -// request(pet_url, function (err, response, body) {
25 -// if (err) {
26 -// console.log(`err => ${err}`)
27 -// }
28 -// else {
29 -// if (res.statusCode == 200) {
30 -// var hospital_list = [];
31 -// var titles = '';
32 -// var result = convert.xml2json(body, { compact: true, spaces: 4 });
33 -// var petJson = JSON.parse(result);
34 -// var itemList = petJson.response.body.items;
35 -// var numRows = petJson.response.body.totalCount._text; //개수
36 -// if (numRows == 1) {
37 -// // state 정상인 것만 추리기
38 -// if (itemList.item.state._text == '정상') {
39 -// appliance_list.push(itemList.item);
40 -// }
41 -// }
42 -// else if (numRows == 0) { }
43 -// else {
44 -// for (i = 0; i < numRows; i++) {
45 -// // state 정상인 것만 추리기
46 -// if (itemList.item[i].state._text == '정상') {
47 -// appliance_list.push(itemList.item[i]);
48 -// }
49 -// }
50 -// }
51 -
52 -// //테스트용 console.log
53 -// for (i = 0; i < hospital_list.length; i++) {
54 -// titles = titles + hospital_list[i].title._text + '\n';
55 -// }
56 -// if (titles == '') { console.log('nothing'); }
57 -// else { console.log(titles); }
58 -// }
59 -// }
60 -// res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list });
61 -// })
62 -// });
63 -// 사용자가 index 페이지에서 주소를 입력하고 넘어오면
64 router.post('/', function (req, res) { 14 router.post('/', function (req, res) {
65 var body = req.body; 15 var body = req.body;
66 gu_select = body.user_gu; 16 gu_select = body.user_gu;
...@@ -68,6 +18,7 @@ router.post('/', function (req, res) { ...@@ -68,6 +18,7 @@ router.post('/', function (req, res) {
68 18
69 }); 19 });
70 20
21 +//동물병원 함수
71 router.get('/hospital', function (req, res) { 22 router.get('/hospital', function (req, res) {
72 //api 23 //api
73 var gu_select_encode = urlencode(gu_select); 24 var gu_select_encode = urlencode(gu_select);
...@@ -104,65 +55,50 @@ router.get('/hospital', function (req, res) { ...@@ -104,65 +55,50 @@ router.get('/hospital', function (req, res) {
104 55
105 //동물약국 56 //동물약국
106 router.get('/medicine', function (req, res) { 57 router.get('/medicine', function (req, res) {
107 - //gu 받아오기 58 + //api
108 - var body = req.body; 59 + var gu_select_encode = urlencode(gu_select);
109 - var gu_select = body.user_gu;
110 var menu = '동물약국'; 60 var menu = '동물약국';
111 - // encoding for url
112 var menu_encode = urlencode(menu); 61 var menu_encode = urlencode(menu);
113 - var gu_select_encode = urlencode(gu_select); 62 +
114 - //api 63 +
115 - let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=200&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`; 64 + let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`;
116 request(pet_url, function (err, response, body) { 65 request(pet_url, function (err, response, body) {
117 if (err) { 66 if (err) {
118 console.log(`err => ${err}`) 67 console.log(`err => ${err}`)
119 } 68 }
120 else { 69 else {
121 if (res.statusCode == 200) { 70 if (res.statusCode == 200) {
122 - var medicine_list = []; 71 + let category_list = [];
123 - var titles = '';
124 var result = convert.xml2json(body, { compact: true, spaces: 4 }); 72 var result = convert.xml2json(body, { compact: true, spaces: 4 });
125 - var petJson = JSON.parse(result); 73 + var petJson = JSON.parse(result)
126 var itemList = petJson.response.body.items; 74 var itemList = petJson.response.body.items;
127 - var numRows = petJson.response.body.totalCount._text; //개수 75 + var numRows = itemList.item.length; //개수
128 - 76 + for (i = 0; i < numRows; i++) {
129 - if (numRows == 1) {
130 // state 정상인 것만 추리기 77 // state 정상인 것만 추리기
131 - if (itemList.item.state._text == '정상') { 78 + if (itemList.item[i].state._text == '정상') {
132 - appliance_list.push(itemList.item); 79 + category_list.push(itemList.item[i]);
133 - }
134 - }
135 - else if (numRows == 0) { }
136 - else {
137 - for (i = 0; i < numRows; i++) {
138 - // state 정상인 것만 추리기
139 - if (itemList.item[i].state._text == '정상') {
140 - appliance_list.push(itemList.item[i]);
141 - }
142 } 80 }
143 } 81 }
144 -
145 //테스트용 console.log 82 //테스트용 console.log
146 - for (i = 0; i < medicine_list.length; i++) { 83 + var titles = '';
147 - titles = titles + medicine_list[i].title._text + '\n'; 84 + for (i = 0; i < category_list.length; i++) {
85 + titles = titles + category_list[i].title._text + '\n';
148 } 86 }
149 - if (titles == '') { console.log('nothing'); } 87 + console.log(titles);
150 - else { console.log(titles); } 88 + res.render('result', { category: 'medicine', titles: titles, category_list: category_list });
151 } 89 }
152 } 90 }
153 - res.render('result', { category: 'medicine', titles: titles, medicine_list: medicine_list });
154 }) 91 })
155 }); 92 });
93 +
156 //의료기기 94 //의료기기
157 router.get('/appliance', function (req, res) { 95 router.get('/appliance', function (req, res) {
158 - //gu 받아오기
159 - var body = req.body;
160 - var gu_select = body.user_gu;
161 - var menu = "동물의료기기 판매 및 임대업체";
162 - // encoding for url
163 - var menu_encode = urlencode(menu);
164 - var gu_select_encode = urlencode(gu_select);
165 //api 96 //api
97 + var gu_select_encode = urlencode(gu_select);
98 + var menu = '동물의료기기판매및임대업체';
99 + var menu_encode = urlencode(menu);
100 +
101 +
166 let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`; 102 let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu_encode}&where=${gu_select_encode}`;
167 request(pet_url, function (err, response, body) { 103 request(pet_url, function (err, response, body) {
168 if (err) { 104 if (err) {
...@@ -170,47 +106,33 @@ router.get('/appliance', function (req, res) { ...@@ -170,47 +106,33 @@ router.get('/appliance', function (req, res) {
170 } 106 }
171 else { 107 else {
172 if (res.statusCode == 200) { 108 if (res.statusCode == 200) {
173 - var appliance_list = []; 109 + let category_list = [];
174 - var titles = '';
175 var result = convert.xml2json(body, { compact: true, spaces: 4 }); 110 var result = convert.xml2json(body, { compact: true, spaces: 4 });
176 - var petJson = JSON.parse(result); 111 + var petJson = JSON.parse(result)
177 var itemList = petJson.response.body.items; 112 var itemList = petJson.response.body.items;
178 - var numRows = petJson.response.body.totalCount._text; //개수 113 + var numRows = itemList.item.length; //개수
179 - //------------------------------------------------- 114 + for (i = 0; i < numRows; i++) {
180 - if (numRows == 1) {
181 // state 정상인 것만 추리기 115 // state 정상인 것만 추리기
182 - if (itemList.item.state._text == '정상') { 116 + if (itemList.item[i].state._text == '정상') {
183 - appliance_list.push(itemList.item); 117 + category_list.push(itemList.item[i]);
184 - }
185 - }
186 - else if (numRows == 0) { }
187 - else {
188 - for (i = 0; i < numRows; i++) {
189 - // state 정상인 것만 추리기
190 - if (itemList.item[i].state._text == '정상') {
191 - appliance_list.push(itemList.item[i]);
192 - }
193 } 118 }
194 } 119 }
195 - //-----------------------------------------------
196 -
197 //테스트용 console.log 120 //테스트용 console.log
198 - for (i = 0; i < appliance_list.length; i++) { 121 + var titles = '';
199 - titles = titles + appliance_list[i].title._text + '\n'; 122 + for (i = 0; i < category_list.length; i++) {
123 + titles = titles + category_list[i].title._text + '\n';
200 } 124 }
201 - if (titles == '') { console.log('nothing'); } 125 + console.log(titles);
202 - else { console.log(titles); } 126 + res.render('result', { category: 'appliance', titles: titles, category_list: category_list });
203 -
204 } 127 }
205 } 128 }
206 - res.render('result', { category: 'appliance', titles: titles, appliance_list: appliance_list });
207 }) 129 })
208 }); 130 });
131 +
132 +
133 +
209 //체육시설 134 //체육시설
210 router.post('/park', function (req, res) { 135 router.post('/park', function (req, res) {
211 - //gu 받아오기
212 - var body = req.body;
213 - var gu_select = body.user_gu;
214 var menu = ["생활체육관", "학교체육시설", "풋살장", "축구장"]; 136 var menu = ["생활체육관", "학교체육시설", "풋살장", "축구장"];
215 // encoding for url 137 // encoding for url
216 var menu_encode = []; 138 var menu_encode = [];
......
...@@ -15,5 +15,5 @@ ...@@ -15,5 +15,5 @@
15 </tbody> 15 </tbody>
16 </table> 16 </table>
17 <p class="sum">총 개수 : 17 <p class="sum">총 개수 :
18 - <%=appliance_list.length%> 18 + <%=category_list.length%>
19 </p> 19 </p>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -16,5 +16,5 @@ ...@@ -16,5 +16,5 @@
16 </tbody> 16 </tbody>
17 </table> 17 </table>
18 <p class="sum">총 동물약국 개수 : 18 <p class="sum">총 동물약국 개수 :
19 - <%-medicine_list.length%> 19 + <%-category_list.length%>
20 </p> 20 </p>
...\ No newline at end of file ...\ No newline at end of file
......