Showing
1 changed file
with
125 additions
and
0 deletions
weather_briefing/server/clothes.js
0 → 100644
1 | +let express = require('express'); | ||
2 | +let bodyParser = require('body-parser'); | ||
3 | +let mongoose = require('mongoose'); | ||
4 | + | ||
5 | +let cors = require('cors'); | ||
6 | +let app = express(); | ||
7 | +app.use(cors()); | ||
8 | + | ||
9 | +let logid=null; | ||
10 | +const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'; | ||
11 | +//const uri = 'mongodb+srv://tahmkench:dkrldnsl7@cluster0.vzipl.mongodb.net/?retryWrites=true&w=majority'; | ||
12 | + | ||
13 | +let db = mongoose.connect(uri, (err) => { | ||
14 | + if (err) { | ||
15 | + console.log(err.message); | ||
16 | + } else { | ||
17 | + console.log('Succesfully Connected!'); | ||
18 | + } | ||
19 | +}); | ||
20 | + | ||
21 | +var clothesSchema = new mongoose.Schema({ | ||
22 | + gender: Number, | ||
23 | + weather: Number, | ||
24 | + top: String, | ||
25 | + bottom:String | ||
26 | +}); | ||
27 | + | ||
28 | +var Clothes = mongoose.model('clothes', clothesSchema); | ||
29 | + | ||
30 | +app.use(bodyParser.json()); | ||
31 | +app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); | ||
32 | + | ||
33 | +app.post('/api/addstyple', (req, res) => { | ||
34 | + | ||
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'}); | ||
37 | + else if (clothes){ | ||
38 | + res.json({ registerSuccess: '0'}); | ||
39 | + } | ||
40 | + else{ | ||
41 | + const new_user = new Clothes(req.body); | ||
42 | + | ||
43 | + new_user.save((err) => { | ||
44 | + if (err) return res.status(500).json({ registerSuccess: '-1'}); | ||
45 | + else return res.status(200).json({ registerSuccess: '1'}); | ||
46 | + }); | ||
47 | + } | ||
48 | + }); | ||
49 | + | ||
50 | +}); | ||
51 | + | ||
52 | +app.post('/api/clothes', (req, res) => { | ||
53 | + | ||
54 | + Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => { | ||
55 | + if (err) return res.status(500).json({ loginSuccess: false }); | ||
56 | + else if (clothes) { | ||
57 | + console.log(clothes); | ||
58 | + // logid={id:clothes.id,password:clothes.password,name:clothes.name,gender:clothes.gender}; | ||
59 | + return res.status(200).json({ loginSuccess: true }); | ||
60 | + } | ||
61 | + else return res.status(404).json({ loginSuccess: false }); | ||
62 | + }); | ||
63 | +}); | ||
64 | + | ||
65 | +app.listen(4000, () => console.log('Server On 4000')); | ||
66 | + | ||
67 | + | ||
68 | + | ||
69 | + | ||
70 | + | ||
71 | + | ||
72 | + | ||
73 | + | ||
74 | + | ||
75 | + | ||
76 | + | ||
77 | + | ||
78 | + | ||
79 | + | ||
80 | + | ||
81 | + | ||
82 | + | ||
83 | + | ||
84 | + | ||
85 | + | ||
86 | + | ||
87 | + | ||
88 | + | ||
89 | + | ||
90 | + | ||
91 | + | ||
92 | + | ||
93 | + | ||
94 | + | ||
95 | + | ||
96 | + | ||
97 | + | ||
98 | + | ||
99 | +// var express = require('express'); | ||
100 | +// var app = express(); | ||
101 | +// var client_id = 'EaHxnjlhHWNjVnHp2eF9'; | ||
102 | +// var client_secret = 'gPbFbMUxq_'; | ||
103 | +// app.get('/search/blog', function (req, res) { | ||
104 | +// var api_url = 'https://openapi.naver.com/v1/search/shop.json?query=' + encodeURI(req.query.query); // json 결과 | ||
105 | +// // var api_url = 'https://openapi.naver.com/v1/search/blog.xml?query=' + encodeURI(req.query.query); // xml 결과 | ||
106 | +// var request = require('request'); | ||
107 | +// var options = { | ||
108 | +// url: api_url, | ||
109 | +// headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret} | ||
110 | +// }; | ||
111 | +// request.get(options, function (error, response, body) { | ||
112 | +// if (!error && response.statusCode == 200) { | ||
113 | +// res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'}); | ||
114 | +// res.end(body); | ||
115 | +// } else { | ||
116 | +// res.status(response.statusCode).end(); | ||
117 | +// console.log('error = ' + response.statusCode); | ||
118 | +// } | ||
119 | +// }); | ||
120 | +// }); | ||
121 | +// app.listen(4000, function () { | ||
122 | +// console.log('http://127.0.0.1:3000/search/blog?query=검색어 app listening on port 3000!'); | ||
123 | +// }); | ||
124 | + | ||
125 | +// // | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment