서주원

implement decklists

1 +const mysql=require('../../database/mysql')
2 +
3 +exports.GetDeck=(res,req)=>{
4 + const userId='test'
5 +
6 + const getDeck=()=>{
7 + return new Promise((resolve,reject)=>{
8 + mysql.getConnection((err,connection)=>{
9 + if (err) throw err
10 + connection.query(`select id,deckTitle from deck where deckOwner=\'${userId}\'`,(err,results,fields)=>{
11 + if (err) throw err
12 + console.log(JSON.stringify(results))
13 + resolve(JSON.stringify(results))
14 + })
15 + connection.release()
16 + })
17 + })
18 +
19 + }
20 + getDeck()
21 + .then((results)=>{
22 + return res.status(200).json(results)
23 + })
24 + .catch((err)=>{
25 + //return res.status(500).json(err||err.message)
26 + })
27 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,7 +2,9 @@ const express=require('express') ...@@ -2,7 +2,9 @@ const express=require('express')
2 const router=express.Router() 2 const router=express.Router()
3 3
4 const newDeck=require('./newDeck') 4 const newDeck=require('./newDeck')
5 +const getDeck=require('./getDeck')
5 6
6 router.post('/newdeck',newDeck.NewDeck) 7 router.post('/newdeck',newDeck.NewDeck)
8 +router.get('/getdeck',getDeck.GetDeck)
7 9
8 module.exports=router 10 module.exports=router
...\ No newline at end of file ...\ No newline at end of file
......
1 -const rp=require('request-promise')
2 -const mysql=require('../../database/mysql')
3 const crawler=require('./crawler') 1 const crawler=require('./crawler')
4 const cheerio=require('cheerio') 2 const cheerio=require('cheerio')
5 const addCards=require('../card/addCards') 3 const addCards=require('../card/addCards')
......
...@@ -8,6 +8,8 @@ const rp=require('request-promise') ...@@ -8,6 +8,8 @@ const rp=require('request-promise')
8 const morgan=require('morgan') 8 const morgan=require('morgan')
9 const cheerio=require('cheerio') 9 const cheerio=require('cheerio')
10 const mysqlApostrophe=require('mysql-apostrophe') 10 const mysqlApostrophe=require('mysql-apostrophe')
11 +const ejs=require('ejs')
12 +const mysql=require('./database/mysql')
11 require('dotenv').config() 13 require('dotenv').config()
12 const app=express() 14 const app=express()
13 15
...@@ -83,9 +85,22 @@ app.get('/decklist',(req,res)=>{ ...@@ -83,9 +85,22 @@ app.get('/decklist',(req,res)=>{
83 if(!req.session.sid) 85 if(!req.session.sid)
84 res.redirect('/login') 86 res.redirect('/login')
85 else{ 87 else{
86 - fs.readFile('./views/html/decklist.html',(err,data)=>{ 88 + mysql.getConnection((err,connection)=>{
89 + if (err) throw err
90 + connection.query(`select id,deckTitle from deck where deckOwner=\'${req.session.sid}\'`,(err,results,fields)=>{
91 + if (err) throw err
92 + else{
93 + console.log(results)
94 + console.log('length : '+results.length)
95 + fs.readFile('./views/ejs/decklist.ejs','utf-8',(err,data)=>{
87 res.writeHead(200,{'Content-Type':'text/html'}) 96 res.writeHead(200,{'Content-Type':'text/html'})
88 - res.end(data) 97 + res.end(ejs.render(data,{
98 + decks:results,
99 + }))
100 + })
101 + }
102 + })
103 + connection.release()
89 }) 104 })
90 } 105 }
91 106
......
...@@ -295,6 +295,11 @@ ...@@ -295,6 +295,11 @@
295 "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 295 "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
296 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 296 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
297 }, 297 },
298 + "ejs": {
299 + "version": "2.6.1",
300 + "resolved": "https://registry.npmjs.org/ejs/-/ejs-2.6.1.tgz",
301 + "integrity": "sha512-0xy4A/twfrRCnkhfk8ErDi5DqdAsAqeGxht4xkCUrsvhhbQNs7E+4jV0CN7+NKIY0aHE72+XvqtBIXzD31ZbXQ=="
302 + },
298 "encodeurl": { 303 "encodeurl": {
299 "version": "1.0.2", 304 "version": "1.0.2",
300 "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 305 "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 "charset": "^1.0.1", 18 "charset": "^1.0.1",
19 "cheerio": "^1.0.0-rc.2", 19 "cheerio": "^1.0.0-rc.2",
20 "dotenv": "^6.1.0", 20 "dotenv": "^6.1.0",
21 + "ejs": "^2.6.1",
21 "express": "^4.16.4", 22 "express": "^4.16.4",
22 "express-session": "^1.15.6", 23 "express-session": "^1.15.6",
23 "fs": "0.0.1-security", 24 "fs": "0.0.1-security",
......
1 +<!DOCTYPE html>
2 +<html lang="ko">
3 +<head>
4 + <meta charset="utf-8">
5 + <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 + <meta name="viewport" content="width=device-width, initial-scale=1">
7 + <title>Who Are You? - 하스스톤 멀리건 도우미</title>
8 +
9 + <!-- 부트스트랩 -->
10 + <link href="../../static/bootstrap-3.3.2-dist/css/bootstrap.min.css?ver=1" rel="stylesheet">
11 + <link href="../../static/main.css" rel="stylesheet">
12 + <!-- IE8 에서 HTML5 요소와 미디어 쿼리를 위한 HTML5 shim 와 Respond.js -->
13 + <!-- WARNING: Respond.js 는 당신이 file:// 을 통해 페이지를 볼 때는 동작하지 않습니다. -->
14 + <!--[if lt IE 9]>
15 + <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
16 + <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
17 + <![endif]-->
18 + <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
19 + <script>
20 + $(document).ready(function(){
21 + $('#logoutButton').click(function(){
22 + $.ajax({
23 + type:'POST',
24 + url:'/logout',
25 + success:function(result){
26 + alert('로그아웃 성공!')
27 + window.location.href='/main'
28 + },
29 + error:function(result){
30 + alert('로그아웃 실패!')
31 + return false
32 + }
33 + })
34 + })
35 + })
36 + </script>
37 +</head>
38 +<body>
39 + <nav class="navbar-default navbar-fixed-top">
40 + <div class="container">
41 + <div class="navbar-header">
42 + <button class="navbar-toggle collapsed" aria-expanded="false" aria-controls="navbar" type="button" data-toggle="collapse" data-target="#navbar">
43 + <span class="sr-only">Toggle navigation</span>
44 + <span class="icon-bar"></span>
45 + <span class="icon-bar"></span>
46 + <span class="icon-bar"></span>
47 + </button>
48 + <a class="navbar-brand" href="/main">Who Are You?</a>
49 + </div>
50 + <div class="navbar-collapse collapse" id="navbar" aria-expanded="false" style="height: 1px;">
51 + <ul class="nav navbar-nav">
52 + </ul>
53 + <div class="navbar-right">
54 + <input type="button" class="btn navbar-btn" id="logoutButton" style="color:#000;" value="로그아웃" />
55 + </div>
56 + </div>
57 + </div>
58 + </nav>
59 +
60 + <div class="container show-grid" >
61 + <div class="padding" style="width:100px"></div>
62 + <div class="container" style="width:50%;">
63 + <div class="row">
64 + <h3 class="form-signin-heading col-md-10" style="text-align: left;">내 덱 리스트</h3>
65 + <a href="/newdeck"><input type="button" class="btn col-md-2" value="+" style="margin-top: 18px;" /></a>
66 + </div>
67 + <br>
68 + <table class="table">
69 + <% for ( var i=0;i<decks.length;i++) { %>
70 + <tr><td style="text-align: center;"><a class="list-group-item" href="/ingame?deck=<%= decks[i].id %>"><%= decks[i].deckTitle %></a></td></tr>
71 + <% } %>
72 + </table>
73 + </div>
74 + </div>
75 +
76 + <!-- jQuery (부트스트랩의 자바스크립트 플러그인을 위해 필요합니다) -->
77 + <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
78 + <!-- 모든 컴파일된 플러그인을 포함합니다 (아래), 원하지 않는다면 필요한 각각의 파일을 포함하세요 -->
79 + <script src="../../static/bootstrap-3.3.2-dist/js/bootstrap.min.js"></script>
80 +</body>
81 +</html>
...\ No newline at end of file ...\ No newline at end of file