Skip to content

Commit 073ac77

Browse files
committed
포스트(post) 객체 리팩토링
포스트 객체에 보드(board)객체를 통합하면서 관련된 내용 모두 수정 포스트 수정과 삭제도 REST API로 변경
1 parent 64b266f commit 073ac77

File tree

11 files changed

+137
-197
lines changed

11 files changed

+137
-197
lines changed

flux/components/Comments.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ module.exports = React.createClass({
1717
return (
1818
<section>
1919
<CommentHeader />
20-
<CommentList flux={this.props.flux} boardId={this.props.board.id} postId={this.props.post.id} comments={this.props.comments} />
21-
<CommentCreateForm flux={this.props.flux} boardId={this.props.board.id} postId={this.props.post.id} />
20+
<CommentList flux={this.props.flux} boardId={this.props.post.board.id} postId={this.props.post.id} comments={this.props.comments} />
21+
<CommentCreateForm flux={this.props.flux} boardId={this.props.post.board.id} postId={this.props.post.id} />
2222
</section>
2323
);
2424
}

flux/components/PostDetail.jsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module.exports = React.createClass({
2727
render() {
2828

2929
var post = this.props.post;
30-
var url = "/boards/" + this.props.board.id;
30+
var board = post.board;
31+
var url = "/boards/" + this.props.post.board.id;
3132
var ModifyButton = false;
3233

3334
if(this.props.post.isOwner){
@@ -42,7 +43,7 @@ module.exports = React.createClass({
4243
<section id="post-detail">
4344
<header className="box">
4445
<div className="title">
45-
<h3><a href={url}> &lt; {this.props.board.name}</a></h3>
46+
<h3><a href={url}> &lt; {board.name}</a></h3>
4647
</div>
4748
{ModifyButton}
4849
</header>
@@ -58,7 +59,7 @@ module.exports = React.createClass({
5859
<div dangerouslySetInnerHTML={{__html: post.content.replace(/\n/g, '</br>') }} />
5960
</article>
6061
</section>
61-
<Comments flux={this.props.flux} user={this.props.user} post={this.props.post} board={this.props.board} comments={this.state.comments}/>
62+
<Comments flux={this.props.flux} user={this.props.user} post={this.props.post} comments={this.state.comments}/>
6263
</section>
6364
);
6465

@@ -67,14 +68,16 @@ module.exports = React.createClass({
6768
handleEditPost(e){
6869
e.preventDefault();
6970

70-
location.href = '/boards/' + this.props.board.id + '/' + this.props.post.id + '/edit';
71+
location.href = '/boards/' + this.props.post.board.id + '/' + this.props.post.id + '/edit';
7172
},
7273

7374
handleDeletePost(e){
7475
e.preventDefault();
7576

7677
var post = this.props.post;
77-
var redirectUrl = "/boards/"+ this.props.board.id;
78+
var board = post.board;
79+
80+
var redirectUrl = "/boards/"+ board.id;
7881
var yes = confirm("정말로 삭제할까요?");
7982

8083
if(!yes) {
@@ -83,7 +86,7 @@ module.exports = React.createClass({
8386

8487
Jquery.ajax({
8588
type: 'DELETE',
86-
url: '/boards/' + this.props.board.id + '/' + post.id
89+
url: '/api/posts/' + post.id
8790
}).done(function(res){
8891
if(res.result === "OK") {
8992
location.href = redirectUrl;

flux/components/PostEditForm.jsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ module.exports = React.createClass({
55

66
getInitialState() {
77
return {
8-
98
title: this.props.post.title,
109
content: this.props.post.content
1110
}
1211
},
1312

1413
render() {
1514

16-
var url = "/boards/" + this.props.board.id;
15+
var url = "/boards/" + this.props.post.board.id;
1716
var formUrl = url + '/' + this.props.post.id;
1817

1918
return (
2019
<section id="post-form">
2120
<form action={formUrl} method="PUT" onSubmit={this.handleEditSubmit}>
2221
<header>
23-
<h4 className="center">{this.props.board.name}</h4>
22+
<h4 className="center">{this.props.post.board.name}</h4>
2423
<input type="button" tabIndex="1" className="btn left" value="취소" onClick={this.handleEditCancle}/>
2524
<input type="submit" tabIndex="4" className="btn right" value="저장" />
2625
</header>
@@ -54,11 +53,11 @@ module.exports = React.createClass({
5453
handleEditSubmit(e){
5554

5655
e.preventDefault();
57-
var redirectUrl = "/boards/"+ this.props.board.id + '/' + this.props.post.id;
56+
var redirectUrl = "/boards/"+ this.props.post.board.id + '/' + this.props.post.id;
5857

5958
Jquery.ajax({
6059
type: 'PUT',
61-
url: '/boards/' + this.props.board.id + '/' + this.props.post.id,
60+
url: '/api/posts/' + this.props.post.id,
6261
data: {
6362
title: this.state.title,
6463
content: this.state.content

flux/components/pages/PostMain.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ module.exports = React.createClass({
2525
return (<PostEditForm board={this.props.board} post={this.props.post}/>);
2626

2727
case 'detail':
28-
return (<PostDetail flux={this.props.flux} board={this.props.board} post={this.props.post}/>);
28+
return (<PostDetail flux={this.props.flux} post={this.props.post}/>);
2929

3030
case 'list':
3131

3232
var posts = this.props.posts;
33-
var linkUrl = "/boards/"+ this.props.board.id +"/newpost";
33+
var linkUrl = "/boards/"+ this.props.board.id +"/write";
3434
return (
3535
<section id="post-main">
3636
<header className="title-box">

server/app/controllers/board.controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ var Company = require('../models/company.model');
66
exports.canAccess = function(req, res, next){
77

88
var member = req.session.user;
9-
var boardId = req.params.boardId;
9+
var regx = /\/boards\/(\w+)/;
10+
var boardId = regx.exec(req.originalUrl)[1];
1011

1112
Board.findOne({where: { id: boardId } })
1213
.then(function(board) {
@@ -19,7 +20,7 @@ exports.canAccess = function(req, res, next){
1920
var type = board.get('type');
2021
var companyId = board.get('companyId');
2122

22-
req.session.board = board;
23+
req.board = board;
2324

2425
// 관리자는 무조건 접근 가능하다.
2526
if( res.locals.isAdmin ){
@@ -32,7 +33,6 @@ exports.canAccess = function(req, res, next){
3233
} else if( type === 'N' || type === 'L' ) {
3334
next();
3435
} else {
35-
delete req.session.board;
3636
res.sendStatus(401);
3737
return;
3838
}

server/app/controllers/company.controller.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)