고병후

Complete board

...@@ -8,29 +8,34 @@ const {Post}=require('../models'); //게시물정보 db연결 ...@@ -8,29 +8,34 @@ const {Post}=require('../models'); //게시물정보 db연결
8 8
9 //현재 로그인된 사용자의 게시물 배열 응답 9 //현재 로그인된 사용자의 게시물 배열 응답
10 router.get('/',auth,(req,res)=>{ 10 router.get('/',auth,(req,res)=>{
11 +
11 Post.findAll({ 12 Post.findAll({
12 - where:{userid: req.session.name} 13 + //where:{userid: req.session.name}
13 }) 14 })
14 .then((result)=>{ 15 .then((result)=>{
16 + //console.log(result);
17 + res.send(result);
15 //게시물이 0개인 경우 18 //게시물이 0개인 경우
16 - if(result === null || result === undefined){ 19 + // if(result === null || result === undefined){
17 - console.log("해당유저의 게시물이 없습니다.") 20 + // console.log("해당유저의 게시물이 없습니다.")
18 - res.status(401).send("null"); 21 + // res.status(401).send("null");
19 - } 22 + // }
20 - else{ 23 + // else{
21 - console.log(result.length); 24 + // console.log(result.length);
22 - res.sendStatus(200); 25 + // res.sendStatus(200);
23 - } 26 + // }
24 - }) 27 + })
25 }); 28 });
29 +
30 +
26 31
27 //게시물 작성 32 //게시물 작성
28 router.post('/',auth,(req,res)=>{ 33 router.post('/',auth,(req,res)=>{
29 try{ 34 try{
30 Post.create({ 35 Post.create({
31 userid : req.session.name, 36 userid : req.session.name,
32 - title : "프로트랑 맞추기", 37 + title : req.body.title,
33 - post:"프론트랑 맞추기", 38 + post: req.body.content,
34 status: false 39 status: false
35 }) 40 })
36 console.log("게시"); 41 console.log("게시");
......
1 - 1 +import Axios from 'axios';
2 -import React, { useState} 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 import ReactHtmlParser from 'react-html-parser';
5 import BoardModal from "../Modal/BoardModal"; 5 import BoardModal from "../Modal/BoardModal";
6 6
7 function Board() { 7 function Board() {
8 const [viewContent,setViewContent] = useState([]); 8 const [viewContent,setViewContent] = useState([]);
9 - const onViewContentHandler = (data) => { 9 +
10 - setViewContent((viewContent.concat({...data}))) 10 + useEffect(()=>{
11 - } 11 + Axios.get('/api/post').then((response)=>{
12 + //console.log(response.data);
13 + setViewContent(response.data);
14 + })
15 + },[viewContent])
12 return ( 16 return (
13 <div className="Board"> 17 <div className="Board">
14 <div className="write-button"> 18 <div className="write-button">
15 - <BoardModal onViewContentHandler={onViewContentHandler}/> 19 + <BoardModal/>
20 + </div>
21 + <div className="contents">
22 + {viewContent&&viewContent.map(element =>{
23 + return <div className="ui segment">
24 + <h2>{element.title}</h2>
25 + <div>
26 + {ReactHtmlParser(element.post)}
27 + </div>
28 + </div>}
29 + )}
16 </div> 30 </div>
17 - {viewContent.map(element =>
18 - <div class="ui segment">
19 -
20 - <h2>{element.title}</h2>
21 - <div>
22 - {ReactHtmlParser(element.content)}
23 - </div>
24 - </div>
25 - )}
26 </div> 31 </div>
27 ); 32 );
28 }; 33 };
29 34
30 -export default Board;
...\ No newline at end of file ...\ No newline at end of file
35 +export default Board;
......
1 import React, {useState} from 'react' 1 import React, {useState} from 'react'
2 -import { Button, Header, Image, Modal } from 'semantic-ui-react' 2 +import Axios from 'axios'
3 +import { Button, Modal } from 'semantic-ui-react'
3 import {CKEditor} from "@ckeditor/ckeditor5-react"; 4 import {CKEditor} from "@ckeditor/ckeditor5-react";
4 import ClassicEditor from "@ckeditor/ckeditor5-build-classic"; 5 import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
5 6
6 -function BoardModal({onViewContentHandler}) { 7 +function BoardModal() {
7 const handleClose = (event) => { 8 const handleClose = (event) => {
8 event.preventDefault(); 9 event.preventDefault();
9 setOpen(false); 10 setOpen(false);
...@@ -11,7 +12,7 @@ function BoardModal({onViewContentHandler}) { ...@@ -11,7 +12,7 @@ function BoardModal({onViewContentHandler}) {
11 const [open, setOpen] = useState(false) 12 const [open, setOpen] = useState(false)
12 const [BoardContent, setBoardContent] = useState({ 13 const [BoardContent, setBoardContent] = useState({
13 title: '', 14 title: '',
14 - content:'' 15 + content:'',
15 }) 16 })
16 const getValue = e => { 17 const getValue = e => {
17 const {name, value} = e.target; 18 const {name, value} = e.target;
...@@ -21,6 +22,29 @@ function BoardModal({onViewContentHandler}) { ...@@ -21,6 +22,29 @@ function BoardModal({onViewContentHandler}) {
21 }) 22 })
22 console.log(BoardContent); 23 console.log(BoardContent);
23 } 24 }
25 + const onSubmitHandler = () => {
26 + Axios.post('/api/post',{
27 + title: BoardContent.title,
28 + content: BoardContent.content,
29 + })
30 + .then((res)=>{
31 + if(res.status === 200){
32 + alert("게시글 작성을 완료하였습니다.")
33 + }
34 + }).catch((error) => {
35 + console.log(error.response)
36 + alert("게시글 작성을 실패하였습니다.")
37 + })
38 + // console.log("ID", Id);
39 + // console.log("Password", Password);
40 + // console.log("MBTI", Personality);
41 + // if (Password !== PasswordCheck) {
42 + // return alert('비밀번호가 일치하지 않습니다.')
43 + // }
44 + // else{
45 + //
46 + // }
47 + }
24 return ( 48 return (
25 <Modal 49 <Modal
26 onClose={() => setOpen(false)} 50 onClose={() => setOpen(false)}
...@@ -34,7 +58,7 @@ function BoardModal({onViewContentHandler}) { ...@@ -34,7 +58,7 @@ function BoardModal({onViewContentHandler}) {
34 </Button>} 58 </Button>}
35 > 59 >
36 <Modal.Header>고민이 있나요?</Modal.Header> 60 <Modal.Header>고민이 있나요?</Modal.Header>
37 - <Modal.Content content> 61 + <Modal.Content >
38 <Modal.Description> 62 <Modal.Description>
39 <div className="form=wrapper"> 63 <div className="form=wrapper">
40 <input className="title-input" 64 <input className="title-input"
...@@ -70,18 +94,18 @@ function BoardModal({onViewContentHandler}) { ...@@ -70,18 +94,18 @@ function BoardModal({onViewContentHandler}) {
70 </Modal.Description> 94 </Modal.Description>
71 </Modal.Content> 95 </Modal.Content>
72 <Modal.Actions> 96 <Modal.Actions>
73 - <div onClick={handleClose}> 97 + <div onClick={handleClose}>
74 - <Button color='black'> 98 + <Button color='black'>
75 - 작성 취소 99 + 작성 취소
76 - </Button> 100 + </Button>
77 - <Button 101 + <Button
78 - content="글 작성하기" 102 + content="글 작성하기"
79 - labelPosition='right' 103 + labelPosition='right'
80 - icon='checkmark' 104 + icon='checkmark'
81 - onClick={()=> onViewContentHandler(BoardContent)} 105 + onClick={onSubmitHandler}
82 - positive 106 + positive
83 - /> 107 + />
84 - </div> 108 + </div>
85 </Modal.Actions> 109 </Modal.Actions>
86 </Modal> 110 </Modal>
87 ) 111 )
......