김건희

[Update] Location File, Clothes, Address

This diff could not be displayed because it is too large.
...@@ -58,15 +58,15 @@ app.post('/api/login', (req, res) => { ...@@ -58,15 +58,15 @@ app.post('/api/login', (req, res) => {
58 Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => { 58 Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
59 if (err) return res.status(500).json({ loginSuccess: false }); 59 if (err) return res.status(500).json({ loginSuccess: false });
60 else if (user) { 60 else if (user) {
61 - return res.status(200).json({ loginSuccess: true }); 61 + logData={name:user.name,gender:user.gender};
62 - } 62 + return res.status(200).json({ loginSuccess: true, logData });
63 + }
63 else return res.status(404).json({ loginSuccess: false }); 64 else return res.status(404).json({ loginSuccess: false });
64 }); 65 });
65 }); 66 });
66 67
67 app.post('/api/logout',(req,res)=>{ 68 app.post('/api/logout',(req,res)=>{
68 - logid=null; 69 + return res.status(200).json({ loginSuccess: false });
69 - res.send('로그아웃 되었습니다.');
70 }); 70 });
71 71
72 //변수들 72 //변수들
...@@ -104,43 +104,44 @@ const sheet=excel.SheetNames[0]; ...@@ -104,43 +104,44 @@ const sheet=excel.SheetNames[0];
104 const first=excel.Sheets[sheet]; 104 const first=excel.Sheets[sheet];
105 const jsonData=xlsx.utils.sheet_to_json(first,{defval:""}); 105 const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
106 let nx,ny; 106 let nx,ny;
107 +
107 app.post('/api/address', (req, res) => { 108 app.post('/api/address', (req, res) => {
108 - let i=0; 109 + const addressList = [];
109 - while(i<3788){ 110 +
110 - if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){ 111 + for (let i = 0; i < jsonData.length; i++) {
111 - nx=jsonData[i].nx; 112 + addressList.push({
112 - ny=jsonData[i].ny; 113 + address1 : jsonData[i].address1,
113 - curaddress=jsonData[i]; 114 + address2 : jsonData[i].address2,
114 - res.json({nx, ny}); 115 + address3 : jsonData[i].address3,
115 - break; 116 + dotX : jsonData[i].nx,
116 - } 117 + dotY : jsonData[i].ny,
117 - i+=1; 118 + });
118 - } 119 + }
119 -}); 120 +
121 + res.json(addressList);
122 +})
120 123
121 let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; 124 let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
122 -//입력받기 125 +
123 app.post('/api/weather',(req,res)=>{ 126 app.post('/api/weather',(req,res)=>{
124 - let Nx = req.body.dotX; 127 + queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D';
125 - let Ny = req.body.dotY;
126 - var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
127 var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; 128 var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
128 129
130 + const nx = req.body.dotX;
131 + const ny = req.body.dotY;
129 queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ 132 queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
130 queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ 133 queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
131 queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ 134 queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
132 queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(base); /* */ 135 queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(base); /* */
133 queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2300'); /* */ 136 queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2300'); /* */
134 - queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(Nx); /*nx*/ 137 + queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/
135 - queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(Ny); /*ny*/ 138 + queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/
136 -
137 request({ 139 request({
138 url: url + queryParams, 140 url: url + queryParams,
139 method: 'GET' 141 method: 'GET'
140 }, function (error, response, body) { 142 }, function (error, response, body) {
141 let ex=JSON.parse(body); 143 let ex=JSON.parse(body);
142 let item=ex.response.body.items.item; 144 let item=ex.response.body.items.item;
143 -
144 let i=0; 145 let i=0;
145 let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; 146 let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
146 while(item[i].fcstDate==CurDay){ 147 while(item[i].fcstDate==CurDay){
...@@ -171,31 +172,36 @@ app.post('/api/weather',(req,res)=>{ ...@@ -171,31 +172,36 @@ app.post('/api/weather',(req,res)=>{
171 result.push(Json); 172 result.push(Json);
172 i+=2; 173 i+=2;
173 } 174 }
175 +
176 + let addressData = {
177 + address1 : req.body.address1,
178 + address2 : req.body.address2,
179 + address3 : req.body.address3
180 + }
181 + result.push(addressData);
174 res.json(result); 182 res.json(result);
175 });//pop:강수확률 tmp:한시간 기온 183 });//pop:강수확률 tmp:한시간 기온
176 }); 184 });
177 185
178 -app.post('/api/tomorrow',(req,res)=>{ 186 +app.post('/api/tommorrow',(req,res)=>{
179 - const nx = req.body.dotX; 187 + queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D';
180 - const ny = req.body.dotY;
181 - var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
182 var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; 188 var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
183 189
190 + const nx = req.body.dotX;
191 + const ny = req.body.dotY;
184 queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ 192 queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
185 queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ 193 queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
186 queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ 194 queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
187 - queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(base); /* */ 195 + queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
188 - queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2300'); /* */ 196 + queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
189 queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/ 197 queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/
190 queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/ 198 queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/
191 -
192 request({ 199 request({
193 url: url + queryParams, 200 url: url + queryParams,
194 method: 'GET' 201 method: 'GET'
195 }, function (error, response, body) { 202 }, function (error, response, body) {
196 let ex=JSON.parse(body); 203 let ex=JSON.parse(body);
197 let item=ex.response.body.items.item; 204 let item=ex.response.body.items.item;
198 -
199 let i=0; 205 let i=0;
200 let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; 206 let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
201 while(item[i].fcstDate==tommorow||item[i].fcstDate==CurDay){ 207 while(item[i].fcstDate==tommorow||item[i].fcstDate==CurDay){
...@@ -263,14 +269,14 @@ app.post('/api/clothes', (req, res) => { ...@@ -263,14 +269,14 @@ app.post('/api/clothes', (req, res) => {
263 Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => { 269 Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => {
264 let randt=Math.floor(Math.random()*clothes.top.length); 270 let randt=Math.floor(Math.random()*clothes.top.length);
265 let randb=Math.floor(Math.random()*clothes.bottom.length); 271 let randb=Math.floor(Math.random()*clothes.bottom.length);
266 - if (err) return res.status(500).json({ MatchingSuccess: false }); 272 + if (err) return res.status(500).json({ MatchingSuccess: false });
267 - else if (clothes) { 273 + else if (clothes) {
268 - if(req.body.rain==1) return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:1,top1:clothes.top[randt],bottom1:clothes.bottom[randb]}) 274 + if(req.body.rain==1) return res.status(200).json({top:"../../../../../img/"+ clothes.top[randt]+".jpg",bottom:"../../../../../img/"+ clothes.bottom[randb]+".jpg",umbrella:1})
269 - else return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:0,top1:clothes.top[randt],bottom1:clothes.bottom[randb]}); 275 + else return res.status(200).json({top:"../../../../../img/"+ clothes.top[randt]+".jpg",bottom:"../../../../../img/"+ clothes.bottom[randb]+".jpg",umbrella:0});
270 276
271 } 277 }
272 - else return res.status(404).json({ MatchingSuccess: false }); 278 + else return res.status(404).json({ MatchingSuccess: false });
273 - }); 279 + });
274 }); 280 });
275 281
276 app.listen(4000, () => console.log('Server On 4000')); 282 app.listen(4000, () => console.log('Server On 4000'));
...\ No newline at end of file ...\ No newline at end of file
......