박권수

feat. search hospital -> page, totalpage

...@@ -73,16 +73,19 @@ exports.searchHospital = async ctx => { ...@@ -73,16 +73,19 @@ exports.searchHospital = async ctx => {
73 page, 73 page,
74 } = ctx.query; 74 } = ctx.query;
75 75
76 + const pageSlice = 5;
77 +
76 const url = 'http://apis.data.go.kr/B551182/hospInfoService1/getHospBasisList1'; 78 const url = 'http://apis.data.go.kr/B551182/hospInfoService1/getHospBasisList1';
77 let queryParams = '?' + encodeURIComponent('ServiceKey') + '=' + process.env.SERVICE_KEY; 79 let queryParams = '?' + encodeURIComponent('ServiceKey') + '=' + process.env.SERVICE_KEY;
78 queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent(page); 80 queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent(page);
79 - queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent(10); 81 + queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent(pageSlice);
80 queryParams += '&' + encodeURIComponent('yadmNm') + '=' + encodeURIComponent(hospitalNm); 82 queryParams += '&' + encodeURIComponent('yadmNm') + '=' + encodeURIComponent(hospitalNm);
81 83
82 const result = await axios.get(url + queryParams); 84 const result = await axios.get(url + queryParams);
83 85
84 ctx.status = 200; 86 ctx.status = 200;
85 ctx.body = { 87 ctx.body = {
88 + totalPage : Math.ceil(result.data.response.body.totalCount / pageSlice),
86 hospitalList : result.data.response.body.items.item, 89 hospitalList : result.data.response.body.items.item,
87 }; 90 };
88 }; 91 };
......