김서연

의료기관 조회시 목록 출력 성공

...@@ -9,42 +9,46 @@ app.set('views','./views') ...@@ -9,42 +9,46 @@ app.set('views','./views')
9 app.set('view engine','pug'); 9 app.set('view engine','pug');
10 app.use(express.static('public')); 10 app.use(express.static('public'));
11 11
12 +
12 //?page=페이지번호&?perPage=페이지당 데이터수 13 //?page=페이지번호&?perPage=페이지당 데이터수
13 const $base_url = `https://api.odcloud.kr/api/apnmOrg/v1/list`; 14 const $base_url = `https://api.odcloud.kr/api/apnmOrg/v1/list`;
14 const $key = '4US0H%2BXj%2BmS8IR4YL0%2BUb9H4CcbTr92QxhYULfOEz1DT%2BZaaos4sRfNh6cmAD2Icli862Ysc31%2BaE4pWywDBIA%3D%3D'; 15 const $key = '4US0H%2BXj%2BmS8IR4YL0%2BUb9H4CcbTr92QxhYULfOEz1DT%2BZaaos4sRfNh6cmAD2Icli862Ysc31%2BaE4pWywDBIA%3D%3D';
15 -
16 -//임시 매개변수
17 const $page=1; 16 const $page=1;
18 -const $perPage=10; 17 +const $perPage=30000;
19 18
20 const $api_url = $base_url + '?serviceKey='+$key+'&page='+$page+'&perPage='+$perPage; 19 const $api_url = $base_url + '?serviceKey='+$key+'&page='+$page+'&perPage='+$perPage;
21 console.log($api_url); 20 console.log($api_url);
22 21
23 //해당 URL로 요청 22 //해당 URL로 요청
24 -request($api_url,function(err,res,body){ 23 +app.post('/',function(req,res,next){
25 - if(err) throw err; 24 + const searchWord = req.body.region; //지역 키워드
26 - 25 +
27 - var obj = JSON.parse(body); 26 + request($api_url,function(err,response,body){
28 - // console.log(obj); 27 + if(err) throw err;
29 - for(var i=0; i<obj.data.length; i++){ 28 +
30 - let name = obj.data[i].orgnm; 29 + //data부분만 추출
31 - let location = obj.data[i].orgZipaddr; 30 + var obj = JSON.parse(body).data;
32 - console.log(`기관명: ${name}, 위치: ${location}\n`); 31 +
33 - } 32 + // console.log(obj);
34 - 33 +
35 - // res.render('main', {title: 'misae', data:data, pm10:pm10}) 34 + //검색한 지역 포함한 모든 data 담기
35 + let searchList = obj.filter(searchList => {
36 + return searchList.orgZipaddr.includes(searchWord);
37 + });
38 +
39 + // console.log(searchList);
40 +
41 + //result라는 변수에 담아 결과 보내기
42 + res.render('main', {result:searchList});
43 + })
36 44
37 }) 45 })
38 46
47 +
39 app.listen(3000,function(){ 48 app.listen(3000,function(){
40 console.log('Connected 3000 port!'); 49 console.log('Connected 3000 port!');
41 }); 50 });
42 51
43 -app.post('/search',function(req,res){
44 - res.send('내가 검색한 지역은 ' + req.body.region);
45 -})
46 -
47 app.get('/',function(req,res){ 52 app.get('/',function(req,res){
48 -
49 res.render('main'); 53 res.render('main');
50 }) 54 })
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -2,8 +2,37 @@ html ...@@ -2,8 +2,37 @@ html
2 head 2 head
3 meta(charset='utf-8') 3 meta(charset='utf-8')
4 body 4 body
5 - form(action='/search' method="post")
6 - p
7 - input(type='text' name='region' placeholder='지역')
8 - p
9 - input(type='submit')
...\ No newline at end of file ...\ No newline at end of file
5 + h1 COVID-19 의료기관 검색하기
6 +
7 + form(action='/' method="post")
8 + p
9 + input(type='text' name='region' placeholder='서울시')
10 + input(type='submit')
11 +
12 + //result값 있을때만
13 + if result!=NULL
14 + table
15 + tr
16 + th 기관명
17 + th 기관 전화번호
18 + th 기관 주소
19 + th 휴무일 여부
20 + th 점심 시작시간
21 + th 점심 종료시간
22 + th 진료 시작기간
23 + th 진료 종료시간
24 + -for(i=1; i<result.length; i++)
25 + tr
26 + td= result[i].orgnm
27 + td= result[i].orgTlno
28 + td= result[i].orgZipaddr
29 + td= result[i].hldyYn
30 + td= result[i].lunchSttTm
31 + td= result[i].lunchEndTm
32 + td= result[i].sttTm
33 + td= result[i].endTm
34 +
35 +
36 +
37 +
38 +
...\ No newline at end of file ...\ No newline at end of file
......