yourtoons.js
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var express = require('express');
var async = require('async');
var router = express.Router();
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'soap',
password : '111111',
port : 3306,
database : 'ytmt'
});
function getYourToons(otherUser_name,cb){
//현재 로그인한 유저가 아닌 다른 유저들의 내툰리스트 가져오기
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(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(other_user, function (yourtoon_list) {
callback(null,yourtoon_list);
});
}
],
function(err, results){
res.render('yourtoons', {
yourtoons: results[0]
});
}
);
}
})
module.exports = router;