Showing
2 changed files
with
76 additions
and
27 deletions
... | @@ -11,42 +11,69 @@ var connection = mysql.createConnection({ | ... | @@ -11,42 +11,69 @@ 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){ |
22 | - console.log(yourlist); | 26 | + if(!err2){ |
23 | - }else{ | 27 | + yourlist = rows2; |
24 | - console.log("니툰 리스트 가져오는데 실패했습니다!"); | 28 | + yourlist.map((row)=>{ |
25 | - //throw err; | 29 | + row['username']=otherUser_name |
26 | - } | 30 | + }) |
27 | - }); | 31 | + console.log(yourlist); |
32 | + cb(yourlist); | ||
33 | + }else{ | ||
34 | + console.log(err) | ||
35 | + console.log("니툰 리스트 가져오는데 실패했습니다!"); | ||
36 | + //throw err; | ||
37 | + } | ||
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('/'); |
34 | - }else{ | 47 | + } |
35 | - async.series( | 48 | + |
36 | - [ | 49 | + else{ |
37 | - function(callback){ | ||
38 | - getYourToons(req.user.user_id, function (yourtoon_list) { | ||
39 | - callback(null,yourtoon_list); | ||
40 | - }); | ||
41 | - } | ||
42 | - ], | ||
43 | - function(err, results){ | ||
44 | res.render('yourtoons', { | 50 | res.render('yourtoons', { |
45 | - yourtoons: results[0] | 51 | + yourtoons: [] |
46 | }); | 52 | }); |
47 | - } | 53 | + } |
48 | - ); | ||
49 | - } | ||
50 | }); | 54 | }); |
51 | 55 | ||
56 | +router.post('/search', (req,res)=>{ | ||
57 | + const {other_user} = req.body; | ||
58 | + if(!req.isAuthenticated()){ | ||
59 | + res.redirect('/yourtoons'); | ||
60 | + }else{ | ||
61 | + async.series( | ||
62 | + [ | ||
63 | + function(callback){ | ||
64 | + getYourToons(other_user, function (yourtoon_list) { | ||
65 | + callback(null,yourtoon_list); | ||
66 | + }); | ||
67 | + } | ||
68 | + ], | ||
69 | + function(err, results){ | ||
70 | + res.render('yourtoons', { | ||
71 | + yourtoons: results[0] | ||
72 | + }); | ||
73 | + } | ||
74 | + ); | ||
75 | +} | ||
76 | +}) | ||
77 | + | ||
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"> | ... | ... |
-
Please register or login to post a comment