Showing
9 changed files
with
22 additions
and
30 deletions
... | @@ -3,6 +3,10 @@ const Sequelize = require('sequelize'); | ... | @@ -3,6 +3,10 @@ const Sequelize = require('sequelize'); |
3 | module.exports = class Comment extends Sequelize.Model { | 3 | module.exports = class Comment extends Sequelize.Model { |
4 | static init(sequelize) { | 4 | static init(sequelize) { |
5 | return super.init({ | 5 | return super.init({ |
6 | + postid:{ | ||
7 | + type: Sequelize.INTEGER, | ||
8 | + allowNull: false, | ||
9 | + }, | ||
6 | userid:{ | 10 | userid:{ |
7 | type: Sequelize.STRING(30), | 11 | type: Sequelize.STRING(30), |
8 | allowNull: false, | 12 | allowNull: false, |
... | @@ -31,6 +35,6 @@ module.exports = class Comment extends Sequelize.Model { | ... | @@ -31,6 +35,6 @@ module.exports = class Comment extends Sequelize.Model { |
31 | 35 | ||
32 | 36 | ||
33 | static associate(db) { | 37 | static associate(db) { |
34 | - db.Comment.belongsTo(db.Post,{foreignKey: 'postid', targetKey:'id' }); | 38 | + //db.Comment.belongsTo(db.Post,{foreignKey: 'postid', targetKey:'id' }); |
35 | } | 39 | } |
36 | }; | 40 | }; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -35,6 +35,6 @@ module.exports = class Post extends Sequelize.Model { | ... | @@ -35,6 +35,6 @@ module.exports = class Post extends Sequelize.Model { |
35 | 35 | ||
36 | static associate(db) { | 36 | static associate(db) { |
37 | db.Post.belongsTo(db.User,{foreignKey: 'userid', targetKey:'name' }); | 37 | db.Post.belongsTo(db.User,{foreignKey: 'userid', targetKey:'name' }); |
38 | - db.Post.hasMany(db.Post,{foreignKey: 'postid', sourceKey:'id' }); | 38 | + //db.Post.hasMany(db.Post,{foreignKey: 'postid', sourceKey:'id' }); |
39 | } | 39 | } |
40 | }; | 40 | }; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -11,7 +11,7 @@ const {Comment}=require('../models'); | ... | @@ -11,7 +11,7 @@ const {Comment}=require('../models'); |
11 | router.get('/:boardId',auth,(req,res)=>{ | 11 | router.get('/:boardId',auth,(req,res)=>{ |
12 | 12 | ||
13 | Comment.findAll({ | 13 | Comment.findAll({ |
14 | - where:{postid: req.params.boardId}, | 14 | + where:{postid: req.params.id}, |
15 | order: [['created_at', 'ASC']], | 15 | order: [['created_at', 'ASC']], |
16 | }) | 16 | }) |
17 | .then((result)=>{ | 17 | .then((result)=>{ |
... | @@ -36,7 +36,7 @@ router.post('/:boardId',auth,(req,res)=>{ | ... | @@ -36,7 +36,7 @@ router.post('/:boardId',auth,(req,res)=>{ |
36 | try{ | 36 | try{ |
37 | Comment.create({ | 37 | Comment.create({ |
38 | userid : req.session.name, | 38 | userid : req.session.name, |
39 | - postid : req.params.boardId, | 39 | + postid : req.body.id, |
40 | comment : req.body.comment, | 40 | comment : req.body.comment, |
41 | }) | 41 | }) |
42 | console.log("게시"); | 42 | console.log("게시"); | ... | ... |
... | @@ -10,8 +10,8 @@ const {Post}=require('../models'); //게시물정보 db연결 | ... | @@ -10,8 +10,8 @@ const {Post}=require('../models'); //게시물정보 db연결 |
10 | router.get('/',auth,(req,res)=>{ | 10 | router.get('/',auth,(req,res)=>{ |
11 | 11 | ||
12 | Post.findAll({ | 12 | Post.findAll({ |
13 | - where:{userid: req.session.name}, | 13 | + // where:{userid: req.session.name}, |
14 | - order: [['created_at', 'DESC']], | 14 | + // order: [['created_at', 'DESC']], |
15 | }) | 15 | }) |
16 | .then((result)=>{ | 16 | .then((result)=>{ |
17 | //console.log(result); | 17 | //console.log(result); | ... | ... |
1 | import Axios from 'axios'; | 1 | import Axios from 'axios'; |
2 | import React, { useState, useEffect} from 'react'; | 2 | import React, { useState, useEffect} from 'react'; |
3 | import '../style/Board.scss' | 3 | import '../style/Board.scss' |
4 | -import ReactHtmlParser from 'react-html-parser'; | 4 | + |
5 | import BoardModal from "../Modal/BoardModal"; | 5 | import BoardModal from "../Modal/BoardModal"; |
6 | import ContentModal from '../Modal/ContentModal'; | 6 | import ContentModal from '../Modal/ContentModal'; |
7 | 7 | ... | ... |
... | @@ -4,6 +4,7 @@ import { Button, Modal } from 'semantic-ui-react' | ... | @@ -4,6 +4,7 @@ import { Button, Modal } from 'semantic-ui-react' |
4 | import {CKEditor} from "@ckeditor/ckeditor5-react"; | 4 | import {CKEditor} from "@ckeditor/ckeditor5-react"; |
5 | import ClassicEditor from "@ckeditor/ckeditor5-build-classic"; | 5 | import ClassicEditor from "@ckeditor/ckeditor5-build-classic"; |
6 | 6 | ||
7 | + | ||
7 | function BoardModal() { | 8 | function BoardModal() { |
8 | const handleClose = (event) => { | 9 | const handleClose = (event) => { |
9 | event.preventDefault(); | 10 | event.preventDefault(); | ... | ... |
... | @@ -17,22 +17,19 @@ function ContentModal({element}) { | ... | @@ -17,22 +17,19 @@ function ContentModal({element}) { |
17 | setOpen(false); | 17 | setOpen(false); |
18 | } | 18 | } |
19 | const [open, setOpen] = useState(false) | 19 | const [open, setOpen] = useState(false) |
20 | - const [BoardComment, setBoardComment] = useState({ | 20 | + const [BoardComment, setBoardComment] = useState('') |
21 | - id: null, | ||
22 | - content:'' | ||
23 | - }) | ||
24 | const onCommentHandler = (event) => { | 21 | const onCommentHandler = (event) => { |
25 | setBoardComment(event.currentTarget.value) | 22 | setBoardComment(event.currentTarget.value) |
26 | console.log(BoardComment) | 23 | console.log(BoardComment) |
27 | } | 24 | } |
28 | - const onSubmitHandler = () => { | 25 | + const onSubmitHandler = () => { |
29 | - Axios.post('/api/comment',{ | 26 | + Axios.post(`/api/comment${element.id}`,{ |
30 | - id: element.id, | ||
31 | content: BoardComment | 27 | content: BoardComment |
32 | }) | 28 | }) |
33 | .then((res)=>{ | 29 | .then((res)=>{ |
34 | if(res.status === 200){ | 30 | if(res.status === 200){ |
35 | alert("댓글 작성을 완료하였습니다.") | 31 | alert("댓글 작성을 완료하였습니다.") |
32 | + setOpen(false); | ||
36 | } | 33 | } |
37 | }).catch((error) => { | 34 | }).catch((error) => { |
38 | console.log(error.response) | 35 | console.log(error.response) |
... | @@ -59,18 +56,18 @@ function ContentModal({element}) { | ... | @@ -59,18 +56,18 @@ function ContentModal({element}) { |
59 | <Modal.Content> | 56 | <Modal.Content> |
60 | {viewComment&&viewComment.map(elem =>{ | 57 | {viewComment&&viewComment.map(elem =>{ |
61 | return <div className="ui segment"> | 58 | return <div className="ui segment"> |
62 | - <h2>{elem.title}</h2> | 59 | + <h2>{elem.id}</h2> |
63 | - <h4>{elem.created_at.slice(0,10)+" " +elem.created_at.slice(11,16)}</h4> | 60 | + <h4>{elem.comment}</h4> |
64 | </div>} | 61 | </div>} |
65 | )} | 62 | )} |
66 | </Modal.Content> | 63 | </Modal.Content> |
67 | <Modal.Actions> | 64 | <Modal.Actions> |
68 | <Comment> | 65 | <Comment> |
69 | <Form reply> | 66 | <Form reply> |
70 | - <Form.TextArea onChange={onCommentHandler}/> | 67 | + <Form.TextArea value={BoardComment} onChange={onCommentHandler}/> |
71 | <div onClick={handleClose}> | 68 | <div onClick={handleClose}> |
72 | - <Button content='댓글 남기기' labelPosition='left' icon='edit' primary onSubmit={onSubmitHandler}/> | 69 | + <Button content='댓글 남기기' onClick={onSubmitHandler} labelPosition='left' icon='edit' primary /> |
73 | - <Button color='black'>닫기</Button> | 70 | + <Button onClick={handleClose} color='black'>닫기</Button> |
74 | </div> | 71 | </div> |
75 | </Form> | 72 | </Form> |
76 | </Comment> | 73 | </Comment> | ... | ... |
... | @@ -43,16 +43,6 @@ | ... | @@ -43,16 +43,6 @@ |
43 | color: white; | 43 | color: white; |
44 | outline: none; | 44 | outline: none; |
45 | } | 45 | } |
46 | - .dropdown{ | ||
47 | - width: 75%; | ||
48 | - padding: 15px .8em .8em; | ||
49 | - background-color: transparent; | ||
50 | - border: 2px solid white; | ||
51 | - border-radius: 30px; | ||
52 | - font-size: 18px; | ||
53 | - color: white; | ||
54 | - outline: none; | ||
55 | - } | ||
56 | 46 | ||
57 | label { | 47 | label { |
58 | position: absolute; | 48 | position: absolute; | ... | ... |
-
Please register or login to post a comment