Seokjin

[UPDATE]getlocation

let express = require('express');
let bodyParser = require('body-parser');
let mongoose = require('mongoose');
let nx,ny;
let app = express();
const cors=require('cors');
app.use(cors);
let logid=null;
const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority';
let db = mongoose.connect(uri, (err) => {
......@@ -12,12 +15,14 @@ let db = mongoose.connect(uri, (err) => {
console.log('Succesfully Connected!');
}
});
//생년월일을 인자로 추가
var UserSchema = new mongoose.Schema({
name: String,
id: String,
password: String,
gender:Number
gender:String,
//nx:String,
//ny:String
});
var Users = mongoose.model('users', UserSchema);
......@@ -25,7 +30,7 @@ var Users = mongoose.model('users', UserSchema);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ limit: '1gb', extended: false }));
app.post('/signup', (req, res) => {
app.post('/api/register', (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){
......@@ -35,19 +40,18 @@ app.post('/signup', (req, res) => {
var new_user = new Users(req.body);
new_user.save((err) => {
if (err) return res.status(500).json({ message: '회원가입에 실패하였습니다.' });
else return res.status(200).json({ message: '회원가입이 완료되었습니다.', data: new_user });
if (err) return res.status(500).json({ message: '회원가입에 실패하였습니다.', success: false, err });
else return res.status(200).json({ message: '회원가입이 완료되었습니다.', success: true });
});
}
});
});
app.post('/signin', (req, res) => {
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};
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 });
}
else return res.status(404).json({ message: '아이디와 비밀번호를 다시 확인해주세요.' });
......@@ -57,4 +61,17 @@ app.post('/logout',(req,res)=>{
logid=null;
res.send('로그아웃 되었습니다.');
});
// 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];
// }
// });
app.listen(4000, () => console.log('Server On 4000'));
\ No newline at end of file
......
var request = require('request');
//nx,ny구하기
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.find() 여기서 server.js의 logid의 address123을 입력받아 이 것을 jsonData에서 찾고 싶습니다. nx와 ny에 대입
let nx,ny;
app.post('/address', (req, res) => {
let i=0;
while(i<3788){
if(jsonData[i].address1==req.address1 && jsonData[i].address2==req.address2 && jsonData[i].address3==req.address3){
nx=jsonData[i].nx;
ny=jsonData[i].ny;
break;
}
i+=1;
}
res.send("좌표는 ",nx,ny,"입니다.");
});
//jsonData.find() 여기서 server.js의 logid의 address123을 입력받아 이 것을 찾음 싶습니다. nx와 ny에 대입
//오늘의 날짜 구하기
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();
}
//입력받기
var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */
queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent('20220521'); /* */
queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(CurDay); /* */
queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0200'); /* */
queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent('62'); /*nx*/
queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent('120'); /*ny*/
queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx.toString()); /*nx*/
queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny.toString()); /*ny*/
request({
url: url + queryParams,
......@@ -38,4 +81,7 @@ request({
fcstValue:list.fcstValue
}));
console.log(temp2);
});
app.post('/mainpage', (req, res) => {
});
\ No newline at end of file
......