이혜리

다른 유저 검색 시 니툰리스트 출력

......@@ -11,31 +11,57 @@ var connection = mysql.createConnection({
database : 'ytmt'
});
function getYourToons(id,cb){
function getYourToons(otherUser_name,cb){
//현재 로그인한 유저가 아닌 다른 유저들의 내툰리스트 가져오기
var sqlquery = "SELECT u.username, t.name, t.toon_index, t.thum_link, t.webtoon_link, t.week, t.site FROM user u, user_toon_relation ur, toon t WHERE u.id != '"+id+"' && u.id=ur.user_id && t.toon_index=ur.toon_index;";
console.log(otherUser_name);
var query1 = "SELECT id FROM user WHERE username = '"+otherUser_name+"'";
// var sqlquery = "SELECT u.username, t.name, t.toon_index, t.thum_link, t.webtoon_link, t.week, t.site FROM user u, user_toon_relation ur, toon t WHERE u.username = '"+otherUser_name+"' && ur.user_id = '"+id+"' && t.toon_index=ur.toon_index;";
var query2 = `SELECT t.name,t.toon_index, t.thum_link,t.webtoon_link,t.week, t.site FROM user_toon_relation ur,toon t WHERE ?=ur.user_id && t.toon_index=ur.toon_index;`
//console.log(sqlquery);
var yourlist = new Array();
connection.query(sqlquery,id,function(err,rows,result){
if(!err){
yourlist=rows;
cb(yourlist);
connection.query(query1,(err,rows,re1)=>{
const result = rows[0].id;
console.log(result)
connection.query(query2,result,function(err2,rows2,re2){
if(!err2){
yourlist = rows2;
yourlist.map((row)=>{
row['username']=otherUser_name
})
console.log(yourlist);
cb(yourlist);
}else{
console.log(err)
console.log("니툰 리스트 가져오는데 실패했습니다!");
//throw err;
}
});
})
}
/* GET home page. */
router.get('/', function(req, res, next) {
if(!req.isAuthenticated()){
res.redirect('/');
}
else{
res.render('yourtoons', {
yourtoons: []
});
}
});
router.post('/search', (req,res)=>{
const {other_user} = req.body;
if(!req.isAuthenticated()){
res.redirect('/yourtoons');
}else{
async.series(
[
function(callback){
getYourToons(req.user.user_id, function (yourtoon_list) {
getYourToons(other_user, function (yourtoon_list) {
callback(null,yourtoon_list);
});
}
......@@ -46,7 +72,8 @@ router.get('/', function(req, res, next) {
});
}
);
}
});
}
})
module.exports = router;
\ No newline at end of file
......
......@@ -44,6 +44,21 @@
border-bottom:2px solid #474747;
text-align: center;
}
input{
font-size: 16px;
width: 270px;
padding: 10px;
border: 2px solid #1b5;
outline: none;
}
.search{
width: 50px;
height: 45px;
border: 0px;
background: #1b5a;
outline: none;
color: #ffffff;
}
</style>
</head>
......@@ -72,7 +87,14 @@
<div class="overlay">
<h2>니툰</h2>
<hr>
<p>다른 사용자들의 내툰 리스트입니다</p>
<p>다른 사용자들의 내툰 리스트를 볼 수 있습니다</p>
<br>
<div class="other_toon_search">
<form method="post" action='/yourtoons/search'>
<input type="text" name="other_user" placeholder="누구의 웹툰 리스트를 알고싶니">
<button class="search" type="submit"> 검색 </button>
</form>
</div>
</div>
</div>
<div class="container">
......