Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alreadynyeong committed Dec 20, 2021
2 parents dd7252d + 3ac13ff commit 64bd758
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 28 deletions.
1 change: 1 addition & 0 deletions public/css/board.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ body {
padding: 0;
margin: 0;
background-color:#242424;
overflow: auto;
}
a {
text-decoration: none;
Expand Down
3 changes: 1 addition & 2 deletions public/css/board_view_css.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ a {
padding: 0 5px;
}
.content{
width: 100%;
height: 50vh;
width: 100%;
text-align: left;
padding-left: 10px;
padding-right: 10px;
Expand Down
28 changes: 24 additions & 4 deletions routes/likeRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ const template = require('../template/likes_list');

// prefix: /likes

function dateFormat(date) {
var newdate = new Date(date);
let month = newdate.getMonth() + 1;
let day = newdate.getDate();

month = month >= 10 ? month : '0' + month;
day = day >= 10 ? day : '0' + day;

return newdate.getFullYear() + '.' + month + '.' + day + ' ';
};


router.get('/', function(request, response) {
console.log(request.user);
if(!request.isAuthenticated()){
Expand All @@ -16,21 +28,27 @@ router.get('/', function(request, response) {
FROM post, liked
WHERE post.id = liked.postId and liked.userId=${request.user.id} group by post.id`,
function(err, result) {
console.log(result);

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

var list ='';
console.log(result[0].createdate)
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>${result[i].createdate}</span></div>
<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>
<input type="image" id="likeImg" src="/public/img/heart_fill.png" disabled='disabled'>
<div class="cnt">${result[i].count}</div>
</div>
</div>
Expand All @@ -40,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
65 changes: 44 additions & 21 deletions routes/myboardRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ const boardlist = require('../template/likes_list.js');

// /myboard

function dateFormat(date) {
var newdate = new Date(date);
let month = newdate.getMonth() + 1;
let day = newdate.getDate();

month = month >= 10 ? month : '0' + month;
day = day >= 10 ? day : '0' + day;

return newdate.getFullYear() + '.' + month + '.' + day + ' ';
};


router.get('/', function(request, response) {
if(!request.isAuthenticated()){
response.send('<script>alert("로그인이 필요한 서비스입니다.");\
Expand All @@ -13,28 +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 ='';
console.log(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>${result[i].createdate}</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 64bd758

Please sign in to comment.