이혜리

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

...@@ -11,31 +11,57 @@ var connection = mysql.createConnection({ ...@@ -11,31 +11,57 @@ var connection = mysql.createConnection({
11 database : 'ytmt' 11 database : 'ytmt'
12 }); 12 });
13 13
14 -function getYourToons(id,cb){ 14 +function getYourToons(otherUser_name,cb){
15 //현재 로그인한 유저가 아닌 다른 유저들의 내툰리스트 가져오기 15 //현재 로그인한 유저가 아닌 다른 유저들의 내툰리스트 가져오기
16 - 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;"; 16 + console.log(otherUser_name);
17 + var query1 = "SELECT id FROM user WHERE username = '"+otherUser_name+"'";
18 + // 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;";
19 + 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;`
20 + //console.log(sqlquery);
17 var yourlist = new Array(); 21 var yourlist = new Array();
18 - connection.query(sqlquery,id,function(err,rows,result){ 22 + connection.query(query1,(err,rows,re1)=>{
19 - if(!err){ 23 + const result = rows[0].id;
20 - yourlist=rows; 24 + console.log(result)
21 - cb(yourlist); 25 + connection.query(query2,result,function(err2,rows2,re2){
26 + if(!err2){
27 + yourlist = rows2;
28 + yourlist.map((row)=>{
29 + row['username']=otherUser_name
30 + })
22 console.log(yourlist); 31 console.log(yourlist);
32 + cb(yourlist);
23 }else{ 33 }else{
34 + console.log(err)
24 console.log("니툰 리스트 가져오는데 실패했습니다!"); 35 console.log("니툰 리스트 가져오는데 실패했습니다!");
25 //throw err; 36 //throw err;
26 } 37 }
27 }); 38 });
39 + })
40 +
28 } 41 }
29 42
30 /* GET home page. */ 43 /* GET home page. */
31 router.get('/', function(req, res, next) { 44 router.get('/', function(req, res, next) {
32 if(!req.isAuthenticated()){ 45 if(!req.isAuthenticated()){
33 res.redirect('/'); 46 res.redirect('/');
47 + }
48 +
49 + else{
50 + res.render('yourtoons', {
51 + yourtoons: []
52 + });
53 + }
54 +});
55 +
56 +router.post('/search', (req,res)=>{
57 + const {other_user} = req.body;
58 + if(!req.isAuthenticated()){
59 + res.redirect('/yourtoons');
34 }else{ 60 }else{
35 async.series( 61 async.series(
36 [ 62 [
37 function(callback){ 63 function(callback){
38 - getYourToons(req.user.user_id, function (yourtoon_list) { 64 + getYourToons(other_user, function (yourtoon_list) {
39 callback(null,yourtoon_list); 65 callback(null,yourtoon_list);
40 }); 66 });
41 } 67 }
...@@ -46,7 +72,8 @@ router.get('/', function(req, res, next) { ...@@ -46,7 +72,8 @@ router.get('/', function(req, res, next) {
46 }); 72 });
47 } 73 }
48 ); 74 );
49 - } 75 +}
50 -}); 76 +})
77 +
51 78
52 module.exports = router; 79 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -44,6 +44,21 @@ ...@@ -44,6 +44,21 @@
44 border-bottom:2px solid #474747; 44 border-bottom:2px solid #474747;
45 text-align: center; 45 text-align: center;
46 } 46 }
47 + input{
48 + font-size: 16px;
49 + width: 270px;
50 + padding: 10px;
51 + border: 2px solid #1b5;
52 + outline: none;
53 + }
54 + .search{
55 + width: 50px;
56 + height: 45px;
57 + border: 0px;
58 + background: #1b5a;
59 + outline: none;
60 + color: #ffffff;
61 + }
47 </style> 62 </style>
48 63
49 </head> 64 </head>
...@@ -72,7 +87,14 @@ ...@@ -72,7 +87,14 @@
72 <div class="overlay"> 87 <div class="overlay">
73 <h2>니툰</h2> 88 <h2>니툰</h2>
74 <hr> 89 <hr>
75 - <p>다른 사용자들의 내툰 리스트입니다</p> 90 + <p>다른 사용자들의 내툰 리스트를 볼 수 있습니다</p>
91 + <br>
92 + <div class="other_toon_search">
93 + <form method="post" action='/yourtoons/search'>
94 + <input type="text" name="other_user" placeholder="누구의 웹툰 리스트를 알고싶니">
95 + <button class="search" type="submit"> 검색 </button>
96 + </form>
97 + </div>
76 </div> 98 </div>
77 </div> 99 </div>
78 <div class="container"> 100 <div class="container">
......