오수빈

add function list_print

...@@ -13,19 +13,9 @@ let user_latitude; ...@@ -13,19 +13,9 @@ let user_latitude;
13 let user_longitude; 13 let user_longitude;
14 let hospital_list = []; 14 let hospital_list = [];
15 15
16 -router.post('/hospital', function(req, res){ 16 +function list_print(res, menu_encode, gu_select_encode){
17 - //gu 받아오기
18 - var body = req.body;
19 - var gu_select = body.user_gu;
20 - //console.log(gu_select);
21 -
22 - // encoding for url
23 - var menu = urlencode('동물병원');
24 - var gu_select_encode = urlencode(gu_select);
25 - //console.log(gu_select_encode);
26 -
27 //api 17 //api
28 - let pet_url = `http://api.kcisa.kr/openapi/service/rest/convergence2019/getConver03?serviceKey=${ANIMAL_INFO_API_KEY}&numOfRows=100&pageNo=1&keyword=${menu}&where=${gu_select_encode}`; 18 + 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}`;
29 request(pet_url, function(err, response, body){ 19 request(pet_url, function(err, response, body){
30 if(err) { 20 if(err) {
31 console.log(`err => ${err}`) 21 console.log(`err => ${err}`)
...@@ -52,7 +42,50 @@ router.post('/hospital', function(req, res){ ...@@ -52,7 +42,50 @@ router.post('/hospital', function(req, res){
52 } 42 }
53 } 43 }
54 res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list }); 44 res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list });
55 - }) 45 + });
46 +}
47 +
48 +router.post('/hospital', function(req, res){
49 + //gu 받아오기
50 + var body = req.body;
51 + var gu_select = body.user_gu;
52 + var menu = '동물병원';
53 +
54 + // encoding for url
55 + var menu_encode = urlencode(menu);
56 + var gu_select_encode = urlencode(gu_select);
57 +
58 + list_print(res, menu_encode, gu_select_encode);
59 +
60 + // //api
61 + // 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}`;
62 + // request(pet_url, function(err, response, body){
63 + // if(err) {
64 + // console.log(`err => ${err}`)
65 + // }
66 + // else {
67 + // if(res.statusCode == 200) {
68 + // var result = convert.xml2json(body, {compact: true, spaces: 4});
69 + // var petJson = JSON.parse(result)
70 + // var itemList = petJson.response.body.items;
71 + // var numRows = itemList.item.length; //개수
72 + // for (i=0; i<numRows; i++){
73 + // // state 정상인 것만 추리기
74 + // if (itemList.item[i].state._text == '정상'){
75 + // hospital_list.push(itemList.item[i]);
76 + // }
77 + // }
78 +
79 + // //테스트용 console.log
80 + // var titles = '';
81 + // for(i=0; i<hospital_list.length; i++){
82 + // titles = titles+hospital_list[i].title._text+'\n';
83 + // }
84 + // console.log(titles);
85 + // }
86 + // }
87 + // res.render('result', { category: 'hospital', titles: titles, hospital_list: hospital_list });
88 + // })
56 }); 89 });
57 90
58 module.exports = router; 91 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......