Skip to content

Commit

Permalink
Merge pull request #34 from HiAlcohol/myboard
Browse files Browse the repository at this point in the history
#33 myboard 라우터 구현, like_list error edit
  • Loading branch information
AYoungSn authored Dec 18, 2021
2 parents 476563c + 7e3c31d commit 98b69dd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion routes/likeRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
41 changes: 41 additions & 0 deletions routes/myboardRouter.js
Original file line number Diff line number Diff line change
@@ -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 += `
<a href='/board/view?id=${result[i].id}'>
<div class="content">
<div class="subject">
<p>${result[i].title}</p>
<div class="info"><span>${request.user.nickname}</span> | <span>${result[i].createdate}</span></div>
</div>
<div class="like">
<button type="button" class="likebtn" id="img_btn"><img src="/public/img/heart_outline.png"></button>
<div class="cnt">${result[i].count}</div>
</div>
</div>
</a>
`
}
const body = boardlist.HOME(list, request.user);
response.send(boardlist.HTML(body));
})

});

module.exports = router;

0 comments on commit 98b69dd

Please sign in to comment.