Skip to content

Commit

Permalink
18.1.저자 수정 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
egoing committed Jun 16, 2018
1 parent 325f399 commit e251ee0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
47 changes: 46 additions & 1 deletion lib/author.js
@@ -1,6 +1,7 @@
var db = require('./db');
var template = require('./template.js');
var qs = require('querystring');
var url = require('url');

exports.home = function(request, response){
db.query(`SELECT * FROM topic`, function(error,topics){
Expand All @@ -26,7 +27,7 @@ exports.home = function(request, response){
<textarea name="profile" placeholder="description"></textarea>
</p>
<p>
<input type="submit">
<input type="submit" value="create">
</p>
</form>
`,
Expand Down Expand Up @@ -58,4 +59,48 @@ exports.create_process = function(request, response){
}
)
});
}

exports.update = function(request, response){
db.query(`SELECT * FROM topic`, function(error,topics){
db.query(`SELECT * FROM author`, function(error2,authors){
var _url = request.url;
var queryData = url.parse(_url, true).query;
db.query(`SELECT * FROM author WHERE id=?`,[queryData.id], function(error3,author){
var title = 'author';
var list = template.list(topics);
var html = template.HTML(title, list,
`
${template.authorTable(authors)}
<style>
table{
border-collapse: collapse;
}
td{
border:1px solid black;
}
</style>
<form action="/author/update_process" method="post">
<p>
<input type="hidden" name="id" value="${queryData.id}">
</p>
<p>
<input type="text" name="name" value="${author[0].name}" placeholder="name">
</p>
<p>
<textarea name="profile" placeholder="description">${author[0].profile}</textarea>
</p>
<p>
<input type="submit" value="update">
</p>
</form>
`,
``
);
response.writeHead(200);
response.end(html);
});

});
});
}
2 changes: 1 addition & 1 deletion lib/template.js
Expand Up @@ -49,7 +49,7 @@ module.exports = {
<tr>
<td>${authors[i].name}</td>
<td>${authors[i].profile}</td>
<td>update</td>
<td><a href="/author/update?id=${authors[i].id}">update</a></td>
<td>delete</td>
</tr>
`
Expand Down
2 changes: 2 additions & 0 deletions main.js
Expand Up @@ -27,6 +27,8 @@ var app = http.createServer(function(request,response){
author.home(request, response);
} else if(pathname === '/author/create_process'){
author.create_process(request, response);
} else if(pathname === '/author/update'){
author.update(request, response);
} else {
response.writeHead(404);
response.end('Not found');
Expand Down

0 comments on commit e251ee0

Please sign in to comment.