Seokjin

[UPDATE]ClothesRecommendation

This diff could not be displayed because it is too large.
......@@ -21,8 +21,8 @@ let db = mongoose.connect(uri, (err) => {
var clothesSchema = new mongoose.Schema({
gender: Number,
weather: Number,
top: String,
bottom:String
top: Array,
bottom:Array
});
var Clothes = mongoose.model('clothes', clothesSchema);
......@@ -30,35 +30,35 @@ var Clothes = mongoose.model('clothes', clothesSchema);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ limit: '1gb', extended: false }));
app.post('/api/addstyple', (req, res) => {
// 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'});
});
}
});
});
// 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 });
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) {
console.log(clothes);
// logid={id:clothes.id,password:clothes.password,name:clothes.name,gender:clothes.gender};
return res.status(200).json({ loginSuccess: true });
return res.status(200).json({top:clothes.top[randt],bottom:clothes.bottom[randb]});
}
else return res.status(404).json({ loginSuccess: false });
else return res.status(404).json({ MatchingSuccess: false });
});
});
......