Seokjin

[Merge] 'weather' into 'backend'

This diff could not be displayed because it is too large.
......@@ -8,13 +8,20 @@
"@testing-library/user-event": "^13.5.0",
"cors": "^2.8.5",
"express": "^4.18.1",
"express-session": "^1.17.3",
"http-proxy-middleware": "^2.0.6",
<<<<<<< HEAD
"mongoose": "^6.3.4",
=======
"mongoose": "^6.3.3",
>>>>>>> origin/weather
"nodemon": "^2.0.16",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
"request": "^2.88.2",
"web-vitals": "^2.1.4",
"xlsx": "^0.18.5"
},
"scripts": {
"start": "react-scripts start",
......
No preview for this file type
let express = require('express');
let bodyParser = require('body-parser');
let mongoose = require('mongoose');
<<<<<<< HEAD
let cors = require('cors');
let app = express();
app.use(cors());
=======
let nx,ny;
let app = express();
const cors=require('cors');
app.use(cors);
>>>>>>> origin/weather
let logid=null;
//const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority';
......@@ -17,12 +24,19 @@ let db = mongoose.connect(uri, (err) => {
console.log('Succesfully Connected!');
}
});
//생년월일을 인자로 추가
var UserSchema = new mongoose.Schema({
name: String,
id: String,
<<<<<<< HEAD
password: String,
gender:String
=======
password: String,
gender:String,
//nx:String,
//ny:String
>>>>>>> origin/weather
});
var Users = mongoose.model('users', UserSchema);
......@@ -31,15 +45,23 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ limit: '1gb', extended: false }));
app.post('/api/register', (req, res) => {
<<<<<<< HEAD
Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
if (err) return res.status(500).json({ registerSuccess: '-1'});
else if (user){
res.json({ registerSuccess: '0'});
=======
Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' });
else if (user){
res.send('이미 존재하는 사용자입니다.');
>>>>>>> origin/weather
}
else{
const new_user = new Users(req.body);
<<<<<<< HEAD
new_user.save((err) => {
if (err) return res.status(500).json({ registerSuccess: '-1'});
else return res.status(200).json({ registerSuccess: '1'});
......@@ -56,6 +78,22 @@ app.post('/api/login', (req, res) => {
else if (user) {
// logid={id:user.id,password:user.password,name:user.name,gender:user.gender};
return res.status(200).json({ loginSuccess: true });
=======
new_user.save((err) => {
if (err) return res.status(500).json({ message: '회원가입에 실패하였습니다.', success: false, err });
else return res.status(200).json({ message: '회원가입이 완료되었습니다.', success: true });
});
}
});
});
app.post('/login', (req, res) => {
Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' });
else if (user){
logid={id:user.id,password:user.password,name:user.name,gender:user.gender,address1:user.address1,address2:user.address2,address3:user.address3};
return res.status(200).json({ message: '로그인 되었습니다.', data: user });
>>>>>>> origin/weather
}
else return res.status(404).json({ loginSuccess: false });
});
......@@ -65,5 +103,21 @@ app.post('/api/logout',(req,res)=>{
logid=null;
res.send('로그아웃 되었습니다.');
});
<<<<<<< HEAD
=======
// const xlsx=require('xlsx');
// const excel=xlsx.readFile('location(x,y).xlsx');
// const sheet=excel.SheetNames[0];
// const first=excel.Sheets[sheet];
// const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
// jsonData.findOne({address1:logid.address1,address2:logid.address2,address3:logid.address3},(err,user)=>{
// if (err) return console.log("일치하는 주소가 없습니다.");
// else if(user){
// tmp=Object.values(user);
// nx=tmp[5];
// ny=tmp[6];
// }
// });
>>>>>>> origin/weather
app.listen(4000, () => console.log('Server On 4000'));
\ No newline at end of file
......
var request = require('request');
let express = require('express');
let app=express();
let bodyParser = require('body-parser');
let session = require('express-session')
app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//nx,ny구하기
//변수들
let curaddress;
var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
//nx,ny구하기
const xlsx=require('xlsx')
const excel=xlsx.readFile('location.xlsx');
const sheet=excel.SheetNames[0];
const first=excel.Sheets[sheet];
const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
let nx,ny,add;
app.post('/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];
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/
queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/
res.send("좌표는 "+nx+" "+ny+"입니다.");
add=req.body.address1+' '+req.body.address2+' '+req.body.address3;
break;
}
i+=1;
}
});
//오늘의 날짜 구하기
let today=new Date();
let CurDay=today.getFullYear().toString();
if(today.getMonth()<9){
CurDay+="0"+(today.getMonth()+1).toString();
}
else{
CurDay+=(today.getMonth()+1).toString();
}
if(today.getDate()<10){
CurDay+="0"+today.getDate().toString();
}
else{
CurDay+=today.getDate().toString();
}
let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
//입력받기
app.post('/mainpage',(req,res)=>{
request({
url: url + queryParams,
method: 'GET'
}, function (error, response, body) {
let ex=JSON.parse(body);
let item=ex.response.body.items.item;
// console.log(items);
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){
if(item[i].category=='POP' || item[i].category=='TMP'){
a.push(item[i]);
}
i+=1;
}
let result=[];
i=0;
while(i<a.length){
let str=CurDay+' '+add+'의 '+a[i].fcstTime[0]+a[i].fcstTime[1]+'시 기온은 '+a[i].fcstValue+'이고, 강수확률은 '+a[i+1].fcstValue+'이다.';
result.push(str);
i+=2;
}//정보를 string으로 저장.
// while(i<a.length){
// let Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].baseTime.fcstValue};
// result.push(Json);
// i+=2;
// }//정보를 Json형식으로 저장.
//return result를 해주고 싶은데 방법을 잘 모르겠음
res.send(result);
});//pop:강수확률 tmp:한시간 기온
});
// app.post('/mainpage', (req, res) => {
// });
app.listen(4000, () => console.log('Server On 5000'));
\ No newline at end of file