Showing
2 changed files
with
53 additions
and
35 deletions
... | @@ -87,22 +87,33 @@ router.get("/login", checkAuthenticated, (req, res) => { | ... | @@ -87,22 +87,33 @@ router.get("/login", checkAuthenticated, (req, res) => { |
87 | 87 | ||
88 | router.post("/login", (req, res) => { | 88 | router.post("/login", (req, res) => { |
89 | //입력을 다하였는지 | 89 | //입력을 다하였는지 |
90 | - if(!req.body.nickname || !req.body.age || !req.body.gender || !req.body.price || !req.body.kindness || !req.body.accessibility ){ | 90 | + if ( |
91 | + !req.body.nickname || | ||
92 | + !req.body.age || | ||
93 | + !req.body.gender || | ||
94 | + !req.body.price || | ||
95 | + !req.body.kindness || | ||
96 | + !req.body.accessibility | ||
97 | + ) { | ||
91 | console.log("입력받지 않은 데이터 존재"); | 98 | console.log("입력받지 않은 데이터 존재"); |
92 | return res.render("login", { | 99 | return res.render("login", { |
93 | user: req.session.user, | 100 | user: req.session.user, |
94 | message: "need data", | 101 | message: "need data", |
95 | }); | 102 | }); |
96 | } | 103 | } |
97 | - var set = new Set([req.body.price, req.body.accessibility, req.body.kindness, req.body.noise]); | 104 | + var set = new Set([ |
105 | + req.body.price, | ||
106 | + req.body.accessibility, | ||
107 | + req.body.kindness, | ||
108 | + req.body.noise, | ||
109 | + ]); | ||
98 | //db에 동일 닉네임있는지 검사(닉네임은 유일해야함) | 110 | //db에 동일 닉네임있는지 검사(닉네임은 유일해야함) |
99 | var sql = " SELECT * FROM USER WHERE NICKNAME=?"; | 111 | var sql = " SELECT * FROM USER WHERE NICKNAME=?"; |
100 | var parameter = [req.body.nickname]; | 112 | var parameter = [req.body.nickname]; |
101 | connection.query(sql, parameter, function (err, row) { | 113 | connection.query(sql, parameter, function (err, row) { |
102 | if (err) { | 114 | if (err) { |
103 | console.log(err); | 115 | console.log(err); |
104 | - } | 116 | + } else if (row.length > 0) { |
105 | - else if (row.length > 0) { | ||
106 | console.log("동일 닉네임있음"); | 117 | console.log("동일 닉네임있음"); |
107 | return res.render("login", { | 118 | return res.render("login", { |
108 | user: req.session.user, | 119 | user: req.session.user, |
... | @@ -110,23 +121,21 @@ router.post("/login", (req, res) => { | ... | @@ -110,23 +121,21 @@ router.post("/login", (req, res) => { |
110 | }); | 121 | }); |
111 | } | 122 | } |
112 | //중복순위제 | 123 | //중복순위제 |
113 | - else if (set.size!=4){ | 124 | + else if (set.size != 4) { |
114 | console.log("중복된 순위 존재"); | 125 | console.log("중복된 순위 존재"); |
115 | return res.render("login", { | 126 | return res.render("login", { |
116 | user: req.session.user, | 127 | user: req.session.user, |
117 | message: "wrong preference", | 128 | message: "wrong preference", |
118 | }); | 129 | }); |
119 | - } | 130 | + } else { |
120 | - else { | ||
121 | req.session.user.nickname = req.body.nickname; | 131 | req.session.user.nickname = req.body.nickname; |
122 | req.session.user.age = req.body.age; | 132 | req.session.user.age = req.body.age; |
123 | req.session.user.gender = req.body.gender; | 133 | req.session.user.gender = req.body.gender; |
124 | - req.session.user.price=req.body.price; | 134 | + req.session.user.price = req.body.price; |
125 | - req.session.user.kindness=req.body.kindness; | 135 | + req.session.user.kindness = req.body.kindness; |
126 | - req.session.user.noise=req.body.noise; | 136 | + req.session.user.noise = req.body.noise; |
127 | - req.session.user.accessibility=req.body.accessibility; | 137 | + req.session.user.accessibility = req.body.accessibility; |
128 | - var sql = | 138 | + var sql = "INSERT INTO USER(EMAIL,NICKNAME, AGE, GENDER) VALUES(?,?,?,?)"; |
129 | - "INSERT INTO USER(EMAIL,NICKNAME, AGE, GENDER) VALUES(?,?,?,?)"; | ||
130 | var parameter = [ | 139 | var parameter = [ |
131 | req.session.user.email, | 140 | req.session.user.email, |
132 | req.session.user.nickname, | 141 | req.session.user.nickname, |
... | @@ -148,7 +157,7 @@ router.post("/login", (req, res) => { | ... | @@ -148,7 +157,7 @@ router.post("/login", (req, res) => { |
148 | req.session.user.price, | 157 | req.session.user.price, |
149 | req.session.user.kindness, | 158 | req.session.user.kindness, |
150 | req.session.user.noise, | 159 | req.session.user.noise, |
151 | - req.session.user.accessibility | 160 | + req.session.user.accessibility, |
152 | ]; | 161 | ]; |
153 | connection.query(sql2, parameter2, function (err) { | 162 | connection.query(sql2, parameter2, function (err) { |
154 | if (err) { | 163 | if (err) { |
... | @@ -156,7 +165,6 @@ router.post("/login", (req, res) => { | ... | @@ -156,7 +165,6 @@ router.post("/login", (req, res) => { |
156 | return res.render("/"); | 165 | return res.render("/"); |
157 | } else { | 166 | } else { |
158 | console.log("새로운 PREFERENCE데이터 입력"); | 167 | console.log("새로운 PREFERENCE데이터 입력"); |
159 | - | ||
160 | } | 168 | } |
161 | }); | 169 | }); |
162 | 170 | ||
... | @@ -192,14 +200,13 @@ router.get("/logout", function (req, res) { | ... | @@ -192,14 +200,13 @@ router.get("/logout", function (req, res) { |
192 | res.redirect("/"); | 200 | res.redirect("/"); |
193 | }); | 201 | }); |
194 | 202 | ||
195 | -router.get("/map", function(req, res, next){ | 203 | +router.get("/map", function (req, res, next) { |
196 | if (req.session.user) { | 204 | if (req.session.user) { |
197 | - res.render("map", {user: req.session.user}); | 205 | + res.render("map", { user: req.session.user }); |
198 | - } | 206 | + } else { |
199 | - else{ | 207 | + res.render("/"); |
200 | - res.render("/") | ||
201 | } | 208 | } |
202 | -}) | 209 | +}); |
203 | 210 | ||
204 | router.get("/review/:cafeId", function (req, res) { | 211 | router.get("/review/:cafeId", function (req, res) { |
205 | const cafeId = req.params.cafeId; | 212 | const cafeId = req.params.cafeId; |
... | @@ -242,28 +249,38 @@ router.post("/review", function (req, res) { | ... | @@ -242,28 +249,38 @@ router.post("/review", function (req, res) { |
242 | ); | 249 | ); |
243 | }); | 250 | }); |
244 | 251 | ||
245 | -router.get("/recommend", function(req, res){ | 252 | +router.get("/recommend", function (req, res) { |
246 | - var sql = "SELECT CAFE_ID FROM REVIEW WHERE PRICE >= ? AND KINDNESS >= ? AND NOISE >= ? AND ACCESSIBILITY >= ?"; | 253 | + console.log(req.session.user); |
247 | - var parameter=[5-req.session.user.price, 5-req.session.user.kindness, 5-req.session.user.noise, 5-req.session.user.accessibility]; | 254 | + |
255 | + var sql = | ||
256 | + "SELECT PRICE, KINDNESS, NOISE, ACCESSIBILITY FROM PREFERENCE WHERE NICKNAME = ?"; | ||
257 | + | ||
258 | + var parameter = req.session.user.nickname; | ||
248 | 259 | ||
249 | connection.query(sql, parameter, function (err, row) { | 260 | connection.query(sql, parameter, function (err, row) { |
250 | - if(err){ | 261 | + if (err) { |
251 | console.log(err); | 262 | console.log(err); |
252 | - }else if (row.length > 0) { //만족하는 조건이 한개도없을때 | 263 | + } else if (row.length > 0) { |
253 | - var parameter2=[4-req.session.user.price, 4-req.session.user.kindness, 4-req.session.user.noise, 4-req.session.user.accessibility]; | 264 | + console.log(row[0]); |
265 | + | ||
266 | + const price = 5 - row[0].PRICE; | ||
267 | + const kindness = 5 - row[0].KINDNESS; | ||
268 | + const noise = 5 - row[0].NOISE; | ||
269 | + const accessibility = 5 - row[0].ACCESSIBILITY; | ||
270 | + | ||
271 | + var sql = | ||
272 | + "SELECT CAFE_ID FROM REVIEW GROUP BY CAFE_ID HAVING AVG(PRICE) >= ? AND AVG(KINDNESS) >= ? AND AVG(NOISE) >= ? AND AVG(ACCESSIBILITY) >= ?"; | ||
254 | 273 | ||
255 | - connection.query(sql, parameter2, function (err, row) { | 274 | + var parameter = [price, kindness, noise, accessibility]; |
256 | - if(err){ | 275 | + |
276 | + connection.query(sql, parameter, function (err, row) { | ||
277 | + if (err) { | ||
257 | console.log(err); | 278 | console.log(err); |
258 | - }else{ | 279 | + } else if (row.length > 0) { |
259 | console.log(row); | 280 | console.log(row); |
260 | - res.render("map", {user: req.session.user}); | 281 | + res.render("map", { user: req.session.user, row: row }); |
261 | } | 282 | } |
262 | }); | 283 | }); |
263 | - | ||
264 | - }else{ | ||
265 | - console.log(row); | ||
266 | - res.render("map", {user: req.session.user}); | ||
267 | } | 284 | } |
268 | }); | 285 | }); |
269 | }); | 286 | }); | ... | ... |
1 | +{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"__lastAccess":1622544019500,"user":{"email":"kdc9619@khu.ac.kr","picture":"https://lh3.googleusercontent.com/a/AATXAJyP14ipRboJZ8T5-oNS3sRp4CG8wKCEwVABQ5G_=s96-c","nickname":"Meerkat","age":26,"gender":"male"}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment