Toggle navigation
Toggle navigation
This project
Loading...
Sign in
오인제
/
Tunnel
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
고병후
2021-12-09 12:47:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a7a00ce3dcec95df5fd17594f215fe752568dfa5
a7a00ce3
1 parent
fea55b99
Make comment effect
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
28 deletions
tunnel_BE/server/models/comment.js
tunnel_BE/server/models/post.js
tunnel_BE/server/routes/comment.js
tunnel_BE/server/routes/post.js
turnel_FE/src/component/views/Modal/ContentModal.js
tunnel_BE/server/models/comment.js
View file @
a7a00ce
...
...
@@ -3,6 +3,10 @@ const Sequelize = require('sequelize');
module
.
exports
=
class
Comment
extends
Sequelize
.
Model
{
static
init
(
sequelize
)
{
return
super
.
init
({
postid
:{
type
:
Sequelize
.
INTEGER
,
allowNull
:
false
,
},
userid
:{
type
:
Sequelize
.
STRING
(
30
),
allowNull
:
false
,
...
...
@@ -31,6 +35,6 @@ module.exports = class Comment extends Sequelize.Model {
static
associate
(
db
)
{
db
.
Comment
.
belongsTo
(
db
.
Post
,{
foreignKey
:
'postid'
,
targetKey
:
'id'
});
//
db.Comment.belongsTo(db.Post,{foreignKey: 'postid', targetKey:'id' });
}
};
\ No newline at end of file
...
...
tunnel_BE/server/models/post.js
View file @
a7a00ce
...
...
@@ -35,6 +35,5 @@ module.exports = class Post extends Sequelize.Model {
static
associate
(
db
)
{
db
.
Post
.
belongsTo
(
db
.
User
,{
foreignKey
:
'userid'
,
targetKey
:
'name'
});
db
.
Post
.
hasMany
(
db
.
Post
,{
foreignKey
:
'postid'
,
sourceKey
:
'id'
});
}
};
\ No newline at end of file
...
...
tunnel_BE/server/routes/comment.js
View file @
a7a00ce
...
...
@@ -7,11 +7,12 @@ const {User}=require('../models'); //유저정보 db연결
const
{
Post
}
=
require
(
'../models'
);
//게시물정보 db연결
const
{
Comment
}
=
require
(
'../models'
);
//현재 로그인된 사용자의 게시물 배열 응답
router
.
get
(
'/:boardId
'
,
auth
,(
req
,
res
)
=>
{
router
.
post
(
'/reply
'
,
auth
,(
req
,
res
)
=>
{
Comment
.
findAll
({
where
:{
postid
:
req
.
params
.
boardI
d
},
where
:{
postid
:
req
.
body
.
i
d
},
order
:
[[
'created_at'
,
'ASC'
]],
})
.
then
((
result
)
=>
{
...
...
@@ -28,15 +29,14 @@ router.get('/:boardId',auth,(req,res)=>{
// }
})
});
//게시물 작성
router
.
post
(
'/:boardId'
,
auth
,(
req
,
res
)
=>
{
router
.
post
(
'/write'
,
auth
,(
req
,
res
)
=>
{
console
.
log
(
req
.
params
.
id
);
try
{
Comment
.
create
({
userid
:
req
.
session
.
name
,
postid
:
req
.
params
.
boardI
d
,
postid
:
req
.
body
.
posti
d
,
comment
:
req
.
body
.
comment
,
})
console
.
log
(
"게시"
);
...
...
@@ -55,5 +55,9 @@ router.post('/:boardId',auth,(req,res)=>{
*/
});
module
.
exports
=
router
;
\ No newline at end of file
...
...
tunnel_BE/server/routes/post.js
View file @
a7a00ce
...
...
@@ -8,9 +8,8 @@ const {Post}=require('../models'); //게시물정보 db연결
//현재 로그인된 사용자의 게시물 배열 응답
router
.
get
(
'/'
,
auth
,(
req
,
res
)
=>
{
Post
.
findAll
({
where
:{
userid
:
req
.
session
.
name
},
//
where:{userid: req.session.name},
order
:
[[
'created_at'
,
'DESC'
]],
})
.
then
((
result
)
=>
{
...
...
turnel_FE/src/component/views/Modal/ContentModal.js
View file @
a7a00ce
...
...
@@ -7,8 +7,8 @@ import '../style/ContentModal.scss'
function
ContentModal
({
element
})
{
const
[
viewComment
,
setviewComment
]
=
useState
([]);
useEffect
(()
=>
{
Axios
.
get
(
'/api/comment/'
+
element
.
id
).
then
((
response
)
=>
{
setviewComment
(
response
.
data
);
Axios
.
post
(
'/api/comment/reply'
,{
id
:
element
.
id
}
).
then
((
response
)
=>
{
setviewComment
(
response
.
data
);
})
},[
viewComment
])
...
...
@@ -17,22 +17,20 @@ function ContentModal({element}) {
setOpen
(
false
);
}
const
[
open
,
setOpen
]
=
useState
(
false
)
const
[
BoardComment
,
setBoardComment
]
=
useState
({
id
:
null
,
content
:
''
})
const
[
BoardComment
,
setBoardComment
]
=
useState
(
""
)
const
onCommentHandler
=
(
event
)
=>
{
setBoardComment
(
event
.
currentTarget
.
value
)
console
.
log
(
BoardComment
)
}
const
onSubmitHandler
=
()
=>
{
Axios
.
post
(
'/api/comment'
,{
id
:
element
.
id
,
cont
ent
:
BoardComment
const
onSubmitHandler
=
()
=>
{
Axios
.
post
(
'/api/comment
/write
'
,{
postid
:
element
.
id
,
comm
ent
:
BoardComment
})
.
then
((
res
)
=>
{
if
(
res
.
status
===
200
){
alert
(
"댓글 작성을 완료하였습니다."
)
setOpen
(
false
);
}
}).
catch
((
error
)
=>
{
console
.
log
(
error
.
response
)
...
...
@@ -57,20 +55,20 @@ function ContentModal({element}) {
<
/Modal.Description
>
<
/Modal.Content
>
<
Modal
.
Content
>
{
viewComment
&&
viewComment
.
map
(
elem
=>
{
{
viewComment
&&
viewComment
.
map
(
elem
=>
{
return
<
div
className
=
"ui segment"
>
<
h2
>
{
elem
.
title
}
<
/h2
>
<
h4
>
{
elem
.
c
reated_at
.
slice
(
0
,
10
)
+
" "
+
elem
.
created_at
.
slice
(
11
,
16
)
}
<
/h4
>
<
h2
>
{
elem
.
userid
}
<
/h2
>
<
h4
>
{
elem
.
c
omment
}
<
/h4
>
<
/div>
}
)}
)}
<
/Modal.Content
>
<
Modal
.
Actions
>
<
Comment
>
<
Comment
>
<
Form
reply
>
<
Form
.
TextArea
onChange
=
{
onCommentHandler
}
/
>
<
Form
.
TextArea
value
=
{
BoardComment
}
onChange
=
{
onCommentHandler
}
/
>
<
div
onClick
=
{
handleClose
}
>
<
Button
content
=
'댓글 남기기'
labelPosition
=
'left'
icon
=
'edit'
primary
onSubmit
=
{
onSubmitHandler
}
/
>
<
Button
color
=
'black'
>
닫기
<
/Button
>
<
Button
content
=
'댓글 남기기'
onClick
=
{
onSubmitHandler
}
labelPosition
=
'left'
icon
=
'edit'
primary
/>
<
Button
onClick
=
{
handleClose
}
color
=
'black'
>
닫기
<
/Button
>
<
/div
>
<
/Form
>
<
/Comment
>
...
...
Please
register
or
login
to post a comment