Seokjin

[UPDATE]Clothes.recommend

let express = require('express');
let bodyParser = require('body-parser');
let mongoose = require('mongoose');
let cors = require('cors');
let app = express();
app.use(cors());
let logid=null;
const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority';
//const uri = 'mongodb+srv://tahmkench:dkrldnsl7@cluster0.vzipl.mongodb.net/?retryWrites=true&w=majority';
let db = mongoose.connect(uri, (err) => {
if (err) {
console.log(err.message);
} else {
console.log('Succesfully Connected!');
}
});
var clothesSchema = new mongoose.Schema({
gender: Number,
weather: Number,
top: String,
bottom:String
});
var Clothes = mongoose.model('clothes', clothesSchema);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ limit: '1gb', extended: false }));
app.post('/api/addstyple', (req, res) => {
Clothes.findOne({ gender: req.body.gender, weather: req.body.weather, top:req.top,bottom:req.bottom }, (err, clothes) => {
if (err) return res.status(500).json({ registerSuccess: '-1'});
else if (clothes){
res.json({ registerSuccess: '0'});
}
else{
const new_user = new Clothes(req.body);
new_user.save((err) => {
if (err) return res.status(500).json({ registerSuccess: '-1'});
else return res.status(200).json({ registerSuccess: '1'});
});
}
});
});
app.post('/api/clothes', (req, res) => {
Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => {
if (err) return res.status(500).json({ loginSuccess: false });
else if (clothes) {
console.log(clothes);
// logid={id:clothes.id,password:clothes.password,name:clothes.name,gender:clothes.gender};
return res.status(200).json({ loginSuccess: true });
}
else return res.status(404).json({ loginSuccess: false });
});
});
app.listen(4000, () => console.log('Server On 4000'));
// var express = require('express');
// var app = express();
// var client_id = 'EaHxnjlhHWNjVnHp2eF9';
// var client_secret = 'gPbFbMUxq_';
// app.get('/search/blog', function (req, res) {
// var api_url = 'https://openapi.naver.com/v1/search/shop.json?query=' + encodeURI(req.query.query); // json 결과
// // var api_url = 'https://openapi.naver.com/v1/search/blog.xml?query=' + encodeURI(req.query.query); // xml 결과
// var request = require('request');
// var options = {
// url: api_url,
// headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret}
// };
// request.get(options, function (error, response, body) {
// if (!error && response.statusCode == 200) {
// res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'});
// res.end(body);
// } else {
// res.status(response.statusCode).end();
// console.log('error = ' + response.statusCode);
// }
// });
// });
// app.listen(4000, function () {
// console.log('http://127.0.0.1:3000/search/blog?query=검색어 app listening on port 3000!');
// });
// //
\ No newline at end of file