From 7e3c31dbd19b90ad437e57e84aa71a9d3f1ec37c Mon Sep 17 00:00:00 2001 From: Ahn YoungSeon Date: Sat, 18 Dec 2021 18:47:09 +0900 Subject: [PATCH] =?UTF-8?q?#33=20myboard=20=EB=9D=BC=EC=9A=B0=ED=84=B0=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84,=20like=5Flist=20error=20edit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 2 ++ routes/likeRouter.js | 2 +- routes/myboardRouter.js | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 routes/myboardRouter.js diff --git a/main.js b/main.js index fda3b24..c32da55 100644 --- a/main.js +++ b/main.js @@ -15,6 +15,7 @@ const search_listRouter = require('./routes/search_listRouter.js'); const mapRouter = require('./routes/mapRouter'); const passportConfig = require('./passport'); const boardProcessRouter = require('./routes/boardProcessRouter.js'); +const myboardRouter = require('./routes/myboardRouter.js'); const env = require('./config/env.js'); const port = env.port; @@ -59,6 +60,7 @@ app.use('/board_process', boardProcessRouter); app.use('/likes', likeRouter); +app.use('/myboard', myboardRouter); app.get('/logout', function(req, res) { req.logout(); diff --git a/routes/likeRouter.js b/routes/likeRouter.js index 97be391..85cc4c4 100644 --- a/routes/likeRouter.js +++ b/routes/likeRouter.js @@ -12,7 +12,7 @@ router.get('/', function(request, response) { } if (request.query.id === undefined) { db.query(`SELECT post.id, post.title, post.createdate, count(*) 'count' - FROM (SELECT * FROM post WHERE post.userId=${request.user.id}) post, liked + FROM post, liked WHERE post.id = liked.postId group by post.id`, function(err, result) { console.log(result); diff --git a/routes/myboardRouter.js b/routes/myboardRouter.js new file mode 100644 index 0000000..5b367b1 --- /dev/null +++ b/routes/myboardRouter.js @@ -0,0 +1,41 @@ +const express = require('express'); +const db = require('../config/db.js'); +const router = express.Router(); +const boardlist = require('../template/likes_list.js'); + +// /myboard + +router.get('/', function(request, response) { + if (request.user === undefined) { + response.redirect('/'); + } + db.query(`SELECT post.id, post.title, post.createdate, count(*) 'count' + FROM (SELECT * FROM post WHERE post.userId=${request.user.id}) post, liked + WHERE post.id = liked.postId group by post.id`, function(err, result) { + if (err) throw err; + console.log(result) + var list =''; + console.log(result[0].createdate) + for (var i = 0;i < result.length; i++) { + list += ` + +
+
+

${result[i].title}

+
${request.user.nickname} | ${result[i].createdate}
+
+ +
+
+ ` + } + const body = boardlist.HOME(list, request.user); + response.send(boardlist.HTML(body)); + }) + +}); + +module.exports = router; \ No newline at end of file