Showing
2 changed files
with
55 additions
and
54 deletions
... | @@ -77,7 +77,7 @@ app.use(express.static(path.join(__dirname, 'public'))); | ... | @@ -77,7 +77,7 @@ app.use(express.static(path.join(__dirname, 'public'))); |
77 | connection = mysql.createConnection({ | 77 | connection = mysql.createConnection({ |
78 | host : 'localhost', | 78 | host : 'localhost', |
79 | user : 'root', | 79 | user : 'root', |
80 | - password : 'asd123', | 80 | + password : '', |
81 | port : 3306, | 81 | port : 3306, |
82 | database : 'ytmt' | 82 | database : 'ytmt' |
83 | }); | 83 | }); | ... | ... |
... | @@ -2,69 +2,70 @@ var express = require('express'); | ... | @@ -2,69 +2,70 @@ var express = require('express'); |
2 | var router = express.Router(); | 2 | var router = express.Router(); |
3 | 3 | ||
4 | function addMyToons(id,index,cb){ | 4 | function addMyToons(id,index,cb){ |
5 | - connection.query("INSERT INTO user_toon_relation SET ?;", {user_id : id,toon_index : index},function (err) { | 5 | + connection.query("INSERT INTO user_toon_relation SET ?;", {user_id : id,toon_index : index},function (err) { |
6 | - if(err) { | 6 | + |
7 | - throw err; | 7 | + if(err) { |
8 | - console.log("내 웹툰 추가 중 에러!") | 8 | + throw err; |
9 | - } else { | 9 | + console.log("내 웹툰 추가 중 에러!") |
10 | - alert("추가되었습니다.") | 10 | + } else{ |
11 | - cb(); | 11 | + // alert("추가되었습니다.") |
12 | - } | 12 | + cb(); |
13 | - }); | 13 | + } |
14 | + }); | ||
14 | } | 15 | } |
15 | 16 | ||
16 | //내툰 수정하기 | 17 | //내툰 수정하기 |
17 | -router.post('/toggle_toon',function(req,res,next) { | 18 | +router.post('/toggle_toon',function(req,res,next){ |
18 | - var index = req.body.toon_index; | 19 | + var index = req.body.toon_index; |
19 | - var id = req.user.user_id; | 20 | + var id = req.user.user_id; |
20 | - connection.query("SELECT COUNT(*) FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"'", [id,index], function (err, rows,result) { | 21 | + connection.query("SELECT COUNT(*) FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"'", [id,index], function (err, rows,result) { |
21 | - if(err) { | 22 | + if(err) { |
22 | - console.log("내 웹툰 등록 중 에러!"); | 23 | + console.log("내 웹툰 등록 중 에러!"); |
23 | - } else { | 24 | + } else { |
24 | - var count = rows[0]["COUNT(*)"]; | 25 | + var count = rows[0]["COUNT(*)"]; |
25 | - if(count > 0) { //이미 등록되어 있는 것이라면, | 26 | + if(count>0) {//이미 등록되어 있는 것이라면, |
26 | - connection.query("DELETE FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"';", [id, index],function (err, rows, result) { | 27 | + connection.query("DELETE FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"';", [id, index],function (err, rows, result) { |
27 | - if(err) { | 28 | + if(err) { |
28 | - console.log("내 웹툰 제거중 에러!"); | 29 | + console.log("내 웹툰 제거중 에러!"); |
29 | - throw err; | 30 | + throw err; |
30 | - } else { | 31 | + } else { |
31 | - alert("제거되었습니다.") | 32 | + //alert("제거되었습니다.") |
32 | - res.redirect('/setting'); | 33 | + res.redirect('/setting'); |
33 | - } | 34 | + } |
34 | - }); | 35 | + }); |
35 | - } else { | 36 | + } else { |
36 | - addMyToons(id,index,function() { | 37 | + addMyToons(id,index,function(){ |
37 | - res.redirect('/setting'); | 38 | + res.redirect('/setting'); |
38 | - }); | 39 | + }); |
39 | - } | 40 | + } |
40 | - } | 41 | + } |
41 | - }); | 42 | + }); |
42 | }); | 43 | }); |
43 | 44 | ||
44 | // | 45 | // |
45 | function getMyToons(id,cb){ | 46 | function getMyToons(id,cb){ |
46 | - //mysql5.7 syntax에 맞게 수정 => 로그인한 유저의 | 47 | + //mysql5.7 syntax에 맞게 수정 => 로그인한 유저의 |
47 | - var sqlquery = "SELECT t.toon_index, t.name, 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;"; | 48 | + var sqlquery = "SELECT t.toon_index, t.name, 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;"; |
48 | - var mylist = new Array(); | 49 | + var mylist = new Array(); |
49 | - connection.query(sqlquery,id,function(err,rows,result) { | 50 | + connection.query(sqlquery,id,function(err,rows,result){ |
50 | - if(!err) { | 51 | + if(!err){ |
51 | - mylist = rows; | 52 | + mylist=rows; |
52 | - cb(mylist); | 53 | + cb(mylist); |
53 | - } else { | 54 | + }else{ |
54 | - router.get('/') | 55 | + router.get('/') |
55 | - console.log("내 웹툰 리스트 가져오는데 실패했습니다!"); | 56 | + console.log("내 웹툰 리스트 가져오는데 실패했습니다!"); |
56 | - //throw err; | 57 | + //throw err; |
57 | - } | 58 | + } |
58 | - }); | 59 | + }); |
59 | } | 60 | } |
60 | 61 | ||
61 | router.get('/', function(req, res, next) { | 62 | router.get('/', function(req, res, next) { |
62 | - getMyToons(req.user.user_id,function (mytoons) { | 63 | + getMyToons(req.user.user_id,function (mytoons) { |
63 | - res.render('setting',{ | 64 | + res.render('setting',{ |
64 | - alltoons : allWebtoons, | 65 | + alltoons : allWebtoons, |
65 | - mytoons : mytoons | 66 | + mytoons : mytoons |
66 | - }); | 67 | + }); |
67 | - }) | 68 | + }) |
68 | }); | 69 | }); |
69 | 70 | ||
70 | module.exports = router; | 71 | module.exports = router; | ... | ... |
-
Please register or login to post a comment