Skip to content

Commit

Permalink
내가 쓴 꿀조합, 좋아요 보기 기능 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
parksewon committed Dec 20, 2021
1 parent 22813c7 commit 393b6c7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
7 changes: 7 additions & 0 deletions routes/likeRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ router.get('/', function(request, response) {
WHERE post.id = liked.postId and liked.userId=${request.user.id} group by post.id`,
function(err, result) {

if(result.length == 0){
response.send('<script>alert("좋아요 기록이 없습니다.");\
location.href="/";</script>');
}else{

var list ='';
var date = dateFormat(result[0].createdate);

Expand All @@ -53,6 +58,8 @@ router.get('/', function(request, response) {
var body = template.HOME(list, request.user);
var html = template.HTML(body);
response.send(html);
}

})
}
});
Expand Down
55 changes: 32 additions & 23 deletions routes/myboardRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,39 @@ router.get('/', function(request, response) {
db.query(`SELECT post.id, post.title, post.createdate, count(liked.id) 'count'
FROM (SELECT * FROM post WHERE post.userId=${request.user.id}) post left join liked
on post.id = liked.postId group by post.id`, function(err, result) {
if (err) throw err;
console.log(result)
var list ='';

var date = dateFormat(result[0].createdate);

for (var i = 0;i < result.length; i++) {
list += `
<div class="content">
<a href='/board/view?id=${result[i].id}'>
<div class="subject">
<p>${result[i].title}</p>
<div class="info"><span>${request.user.nickname}</span> | <span>${date}</span></div>
</div>
</a>
<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>
`

if (result.length == 0){
response.send('<script>alert("작성한 글이 없습니다.");\
location.href="/";</script>');
}else{
if (err) throw err;

var list ='';

var date = dateFormat(result[0].createdate);

for (var i = 0;i < result.length; i++) {
list += `
<div class="content">
<a href='/board/view?id=${result[i].id}'>
<div class="subject">
<p>${result[i].title}</p>
<div class="info"><span>${request.user.nickname}</span> | <span>${date}</span></div>
</div>
</a>
<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>
`
}
const body = boardlist.HOME(list, request.user);
response.send(boardlist.HTML(body));
}
const body = boardlist.HOME(list, request.user);
response.send(boardlist.HTML(body));



})
}
});
Expand Down
2 changes: 1 addition & 1 deletion template/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module.exports = {
</select>
</form>
</div>
<div class="contentList">
<div class="contentList" >
Expand Down

0 comments on commit 393b6c7

Please sign in to comment.