Showing
2 changed files
with
24 additions
and
24 deletions
This diff could not be displayed because it is too large.
... | @@ -21,8 +21,8 @@ let db = mongoose.connect(uri, (err) => { | ... | @@ -21,8 +21,8 @@ let db = mongoose.connect(uri, (err) => { |
21 | var clothesSchema = new mongoose.Schema({ | 21 | var clothesSchema = new mongoose.Schema({ |
22 | gender: Number, | 22 | gender: Number, |
23 | weather: Number, | 23 | weather: Number, |
24 | - top: String, | 24 | + top: Array, |
25 | - bottom:String | 25 | + bottom:Array |
26 | }); | 26 | }); |
27 | 27 | ||
28 | var Clothes = mongoose.model('clothes', clothesSchema); | 28 | var Clothes = mongoose.model('clothes', clothesSchema); |
... | @@ -30,35 +30,35 @@ var Clothes = mongoose.model('clothes', clothesSchema); | ... | @@ -30,35 +30,35 @@ var Clothes = mongoose.model('clothes', clothesSchema); |
30 | app.use(bodyParser.json()); | 30 | app.use(bodyParser.json()); |
31 | app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); | 31 | app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); |
32 | 32 | ||
33 | -app.post('/api/addstyple', (req, res) => { | 33 | +// app.post('/api/addstyple', (req, res) => { |
34 | 34 | ||
35 | - Clothes.findOne({ gender: req.body.gender, weather: req.body.weather, top:req.top,bottom:req.bottom }, (err, clothes) => { | 35 | +// Clothes.findOne({ gender: req.body.gender, weather: req.body.weather, top:req.top,bottom:req.bottom }, (err, clothes) => { |
36 | - if (err) return res.status(500).json({ registerSuccess: '-1'}); | 36 | +// if (err) return res.status(500).json({ registerSuccess: '-1'}); |
37 | - else if (clothes){ | 37 | +// else if (clothes){ |
38 | - res.json({ registerSuccess: '0'}); | 38 | +// res.json({ registerSuccess: '0'}); |
39 | - } | 39 | +// } |
40 | - else{ | 40 | +// else{ |
41 | - const new_user = new Clothes(req.body); | 41 | +// const new_user = new Clothes(req.body); |
42 | - | 42 | + |
43 | - new_user.save((err) => { | 43 | +// new_user.save((err) => { |
44 | - if (err) return res.status(500).json({ registerSuccess: '-1'}); | 44 | +// if (err) return res.status(500).json({ registerSuccess: '-1'}); |
45 | - else return res.status(200).json({ registerSuccess: '1'}); | 45 | +// else return res.status(200).json({ registerSuccess: '1'}); |
46 | - }); | 46 | +// }); |
47 | - } | 47 | +// } |
48 | - }); | 48 | +// }); |
49 | - | 49 | + |
50 | -}); | 50 | +// }); |
51 | 51 | ||
52 | app.post('/api/clothes', (req, res) => { | 52 | app.post('/api/clothes', (req, res) => { |
53 | 53 | ||
54 | Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => { | 54 | Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => { |
55 | - if (err) return res.status(500).json({ loginSuccess: false }); | 55 | + let randt=Math.floor(Math.random()*clothes.top.length); |
56 | + let randb=Math.floor(Math.random()*clothes.bottom.length); | ||
57 | + if (err) return res.status(500).json({ MatchingSuccess: false }); | ||
56 | else if (clothes) { | 58 | else if (clothes) { |
57 | - console.log(clothes); | 59 | + return res.status(200).json({top:clothes.top[randt],bottom:clothes.bottom[randb]}); |
58 | - // logid={id:clothes.id,password:clothes.password,name:clothes.name,gender:clothes.gender}; | ||
59 | - return res.status(200).json({ loginSuccess: true }); | ||
60 | } | 60 | } |
61 | - else return res.status(404).json({ loginSuccess: false }); | 61 | + else return res.status(404).json({ MatchingSuccess: false }); |
62 | }); | 62 | }); |
63 | }); | 63 | }); |
64 | 64 | ... | ... |
-
Please register or login to post a comment