Seokjin

[Merge] 'weather' into 'backend'

This diff could not be displayed because it is too large.
...@@ -8,13 +8,20 @@ ...@@ -8,13 +8,20 @@
8 "@testing-library/user-event": "^13.5.0", 8 "@testing-library/user-event": "^13.5.0",
9 "cors": "^2.8.5", 9 "cors": "^2.8.5",
10 "express": "^4.18.1", 10 "express": "^4.18.1",
11 + "express-session": "^1.17.3",
11 "http-proxy-middleware": "^2.0.6", 12 "http-proxy-middleware": "^2.0.6",
13 +<<<<<<< HEAD
12 "mongoose": "^6.3.4", 14 "mongoose": "^6.3.4",
15 +=======
16 + "mongoose": "^6.3.3",
17 +>>>>>>> origin/weather
13 "nodemon": "^2.0.16", 18 "nodemon": "^2.0.16",
14 "react": "^18.1.0", 19 "react": "^18.1.0",
15 "react-dom": "^18.1.0", 20 "react-dom": "^18.1.0",
16 "react-scripts": "5.0.1", 21 "react-scripts": "5.0.1",
17 - "web-vitals": "^2.1.4" 22 + "request": "^2.88.2",
23 + "web-vitals": "^2.1.4",
24 + "xlsx": "^0.18.5"
18 }, 25 },
19 "scripts": { 26 "scripts": {
20 "start": "react-scripts start", 27 "start": "react-scripts start",
......
No preview for this file type
1 let express = require('express'); 1 let express = require('express');
2 let bodyParser = require('body-parser'); 2 let bodyParser = require('body-parser');
3 let mongoose = require('mongoose'); 3 let mongoose = require('mongoose');
4 +<<<<<<< HEAD
4 5
5 let cors = require('cors'); 6 let cors = require('cors');
6 let app = express(); 7 let app = express();
7 app.use(cors()); 8 app.use(cors());
9 +=======
10 +let nx,ny;
11 +let app = express();
12 +const cors=require('cors');
13 +app.use(cors);
14 +>>>>>>> origin/weather
8 15
9 let logid=null; 16 let logid=null;
10 //const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'; 17 //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) => { ...@@ -17,12 +24,19 @@ let db = mongoose.connect(uri, (err) => {
17 console.log('Succesfully Connected!'); 24 console.log('Succesfully Connected!');
18 } 25 }
19 }); 26 });
20 - 27 +//생년월일을 인자로 추가
21 var UserSchema = new mongoose.Schema({ 28 var UserSchema = new mongoose.Schema({
22 name: String, 29 name: String,
23 id: String, 30 id: String,
31 +<<<<<<< HEAD
24 password: String, 32 password: String,
25 gender:String 33 gender:String
34 +=======
35 + password: String,
36 + gender:String,
37 + //nx:String,
38 + //ny:String
39 +>>>>>>> origin/weather
26 }); 40 });
27 41
28 var Users = mongoose.model('users', UserSchema); 42 var Users = mongoose.model('users', UserSchema);
...@@ -31,15 +45,23 @@ app.use(bodyParser.json()); ...@@ -31,15 +45,23 @@ app.use(bodyParser.json());
31 app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); 45 app.use(bodyParser.urlencoded({ limit: '1gb', extended: false }));
32 46
33 app.post('/api/register', (req, res) => { 47 app.post('/api/register', (req, res) => {
48 +<<<<<<< HEAD
34 49
35 Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => { 50 Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
36 if (err) return res.status(500).json({ registerSuccess: '-1'}); 51 if (err) return res.status(500).json({ registerSuccess: '-1'});
37 else if (user){ 52 else if (user){
38 res.json({ registerSuccess: '0'}); 53 res.json({ registerSuccess: '0'});
54 +=======
55 + Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
56 + if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' });
57 + else if (user){
58 + res.send('이미 존재하는 사용자입니다.');
59 +>>>>>>> origin/weather
39 } 60 }
40 else{ 61 else{
41 const new_user = new Users(req.body); 62 const new_user = new Users(req.body);
42 63
64 +<<<<<<< HEAD
43 new_user.save((err) => { 65 new_user.save((err) => {
44 if (err) return res.status(500).json({ registerSuccess: '-1'}); 66 if (err) return res.status(500).json({ registerSuccess: '-1'});
45 else return res.status(200).json({ registerSuccess: '1'}); 67 else return res.status(200).json({ registerSuccess: '1'});
...@@ -56,6 +78,22 @@ app.post('/api/login', (req, res) => { ...@@ -56,6 +78,22 @@ app.post('/api/login', (req, res) => {
56 else if (user) { 78 else if (user) {
57 // logid={id:user.id,password:user.password,name:user.name,gender:user.gender}; 79 // logid={id:user.id,password:user.password,name:user.name,gender:user.gender};
58 return res.status(200).json({ loginSuccess: true }); 80 return res.status(200).json({ loginSuccess: true });
81 +=======
82 + new_user.save((err) => {
83 + if (err) return res.status(500).json({ message: '회원가입에 실패하였습니다.', success: false, err });
84 + else return res.status(200).json({ message: '회원가입이 완료되었습니다.', success: true });
85 + });
86 + }
87 + });
88 +});
89 +
90 +app.post('/login', (req, res) => {
91 + Users.findOne({ id: req.body.id, password: req.body.password }, (err, user) => {
92 + if (err) return res.status(500).json({ message: '에러가 발생하였습니다.' });
93 + else if (user){
94 + logid={id:user.id,password:user.password,name:user.name,gender:user.gender,address1:user.address1,address2:user.address2,address3:user.address3};
95 + return res.status(200).json({ message: '로그인 되었습니다.', data: user });
96 +>>>>>>> origin/weather
59 } 97 }
60 else return res.status(404).json({ loginSuccess: false }); 98 else return res.status(404).json({ loginSuccess: false });
61 }); 99 });
...@@ -65,5 +103,21 @@ app.post('/api/logout',(req,res)=>{ ...@@ -65,5 +103,21 @@ app.post('/api/logout',(req,res)=>{
65 logid=null; 103 logid=null;
66 res.send('로그아웃 되었습니다.'); 104 res.send('로그아웃 되었습니다.');
67 }); 105 });
106 +<<<<<<< HEAD
68 107
108 +=======
109 +// const xlsx=require('xlsx');
110 +// const excel=xlsx.readFile('location(x,y).xlsx');
111 +// const sheet=excel.SheetNames[0];
112 +// const first=excel.Sheets[sheet];
113 +// const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
114 +// jsonData.findOne({address1:logid.address1,address2:logid.address2,address3:logid.address3},(err,user)=>{
115 +// if (err) return console.log("일치하는 주소가 없습니다.");
116 +// else if(user){
117 +// tmp=Object.values(user);
118 +// nx=tmp[5];
119 +// ny=tmp[6];
120 +// }
121 +// });
122 +>>>>>>> origin/weather
69 app.listen(4000, () => console.log('Server On 4000')); 123 app.listen(4000, () => console.log('Server On 4000'));
...\ No newline at end of file ...\ No newline at end of file
......
1 +var request = require('request');
2 +let express = require('express');
3 +let app=express();
4 +let bodyParser = require('body-parser');
5 +let session = require('express-session')
6 +
7 +app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
8 +app.use(bodyParser.urlencoded({ extended: false }));
9 +app.use(bodyParser.json());
10 +//nx,ny구하기
11 +
12 +//변수들
13 +let curaddress;
14 +var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
15 +var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
16 +
17 +
18 +
19 +
20 +
21 +
22 +//nx,ny구하기
23 +const xlsx=require('xlsx')
24 +const excel=xlsx.readFile('location.xlsx');
25 +const sheet=excel.SheetNames[0];
26 +const first=excel.Sheets[sheet];
27 +const jsonData=xlsx.utils.sheet_to_json(first,{defval:""});
28 +let nx,ny,add;
29 +app.post('/address', (req, res) => {
30 + let i=0;
31 + while(i<3788){
32 + if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){
33 + nx=jsonData[i].nx;
34 + ny=jsonData[i].ny;
35 + curaddress=jsonData[i];
36 + queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
37 + queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
38 + queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
39 + queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
40 + queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
41 + queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/
42 + queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/
43 + res.send("좌표는 "+nx+" "+ny+"입니다.");
44 + add=req.body.address1+' '+req.body.address2+' '+req.body.address3;
45 + break;
46 + }
47 + i+=1;
48 + }
49 +});
50 +
51 +
52 +//오늘의 날짜 구하기
53 +let today=new Date();
54 +let CurDay=today.getFullYear().toString();
55 +if(today.getMonth()<9){
56 + CurDay+="0"+(today.getMonth()+1).toString();
57 +}
58 +else{
59 + CurDay+=(today.getMonth()+1).toString();
60 +}
61 +if(today.getDate()<10){
62 + CurDay+="0"+today.getDate().toString();
63 +}
64 +else{
65 + CurDay+=today.getDate().toString();
66 +}
67 +
68 +
69 +
70 +
71 +
72 +
73 +
74 +
75 +let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
76 +//입력받기
77 +app.post('/mainpage',(req,res)=>{
78 + request({
79 + url: url + queryParams,
80 + method: 'GET'
81 + }, function (error, response, body) {
82 + let ex=JSON.parse(body);
83 + let item=ex.response.body.items.item;
84 + // console.log(items);
85 + let i=0;
86 + let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[];
87 + while(item[i].fcstDate==CurDay){
88 + if(item[i].category=='POP' || item[i].category=='TMP'){
89 + a.push(item[i]);
90 + }
91 + i+=1;
92 + }
93 + let result=[];
94 + i=0;
95 + while(i<a.length){
96 + let str=CurDay+' '+add+'의 '+a[i].fcstTime[0]+a[i].fcstTime[1]+'시 기온은 '+a[i].fcstValue+'이고, 강수확률은 '+a[i+1].fcstValue+'이다.';
97 + result.push(str);
98 + i+=2;
99 + }//정보를 string으로 저장.
100 + // while(i<a.length){
101 + // let Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].baseTime.fcstValue};
102 + // result.push(Json);
103 + // i+=2;
104 + // }//정보를 Json형식으로 저장.
105 + //return result를 해주고 싶은데 방법을 잘 모르겠음
106 + res.send(result);
107 + });//pop:강수확률 tmp:한시간 기온
108 +});
109 +
110 +
111 +
112 +// app.post('/mainpage', (req, res) => {
113 +
114 +// });
115 +
116 +app.listen(4000, () => console.log('Server On 5000'));
...\ No newline at end of file ...\ No newline at end of file