김건희

[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) => {
Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
if (err) return res.status(500).json({ loginSuccess: false });
else if (user) {
return res.status(200).json({ loginSuccess: true });
}
logData={name:user.name,gender:user.gender};
return res.status(200).json({ loginSuccess: true, logData });
}
else return res.status(404).json({ loginSuccess: false });
});
});
app.post('/api/logout',(req,res)=>{
logid=null;
res.send('로그아웃 되었습니다.');
return res.status(200).json({ loginSuccess: false });
});
//변수들
......@@ -104,43 +104,44 @@ const sheet=excel.SheetNames[0];
const first=excel.Sheets[sheet];
const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
let nx,ny;
app.post('/api/address', (req, res) => {
let i=0;
while(i<3788){
if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){
nx=jsonData[i].nx;
ny=jsonData[i].ny;
curaddress=jsonData[i];
res.json({nx, ny});
break;
}
i+=1;
}
});
const addressList = [];
for (let i = 0; i < jsonData.length; i++) {
addressList.push({
address1 : jsonData[i].address1,
address2 : jsonData[i].address2,
address3 : jsonData[i].address3,
dotX : jsonData[i].nx,
dotY : jsonData[i].ny,
});
}
res.json(addressList);
})
let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
//입력받기
app.post('/api/weather',(req,res)=>{
let Nx = req.body.dotX;
let Ny = req.body.dotY;
var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D';
var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
const nx = req.body.dotX;
const ny = req.body.dotY;
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(base); /* */
queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2300'); /* */
queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(Nx); /*nx*/
queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(Ny); /*ny*/
queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/
queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/
request({
url: url + queryParams,
method: 'GET'
}, function (error, response, body) {
let ex=JSON.parse(body);
let item=ex.response.body.items.item;
let i=0;
let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
while(item[i].fcstDate==CurDay){
......@@ -171,31 +172,36 @@ app.post('/api/weather',(req,res)=>{
result.push(Json);
i+=2;
}
let addressData = {
address1 : req.body.address1,
address2 : req.body.address2,
address3 : req.body.address3
}
result.push(addressData);
res.json(result);
});//pop:강수확률 tmp:한시간 기온
});
app.post('/api/tomorrow',(req,res)=>{
const nx = req.body.dotX;
const ny = req.body.dotY;
var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
app.post('/api/tommorrow',(req,res)=>{
queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D';
var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
const nx = req.body.dotX;
const ny = req.body.dotY;
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(base); /* */
queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2300'); /* */
queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/
queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/
request({
url: url + queryParams,
method: 'GET'
}, function (error, response, body) {
let ex=JSON.parse(body);
let item=ex.response.body.items.item;
let i=0;
let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
while(item[i].fcstDate==tommorow||item[i].fcstDate==CurDay){
......@@ -263,14 +269,14 @@ app.post('/api/clothes', (req, res) => {
Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => {
let randt=Math.floor(Math.random()*clothes.top.length);
let randb=Math.floor(Math.random()*clothes.bottom.length);
if (err) return res.status(500).json({ MatchingSuccess: false });
else if (clothes) {
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]})
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]});
if (err) return res.status(500).json({ MatchingSuccess: false });
else if (clothes) {
if(req.body.rain==1) return res.status(200).json({top:"../../../../../img/"+ clothes.top[randt]+".jpg",bottom:"../../../../../img/"+ clothes.bottom[randb]+".jpg",umbrella:1})
else return res.status(200).json({top:"../../../../../img/"+ clothes.top[randt]+".jpg",bottom:"../../../../../img/"+ clothes.bottom[randb]+".jpg",umbrella:0});
}
else return res.status(404).json({ MatchingSuccess: false });
});
else return res.status(404).json({ MatchingSuccess: false });
});
});
app.listen(4000, () => console.log('Server On 4000'));
\ No newline at end of file
......