diff --git a/backend/src/article/articleController.js b/backend/src/article/articleController.js index 921590e90436eb3385e253208f5a9fe76a4f1807..48ba723e5e6e0e166468a3eafab01a8379eaf831 100644 --- a/backend/src/article/articleController.js +++ b/backend/src/article/articleController.js @@ -86,4 +86,34 @@ router.get("/:id", async (req, res) => { res.send(JSON.stringify(articles)); }); +router.post("/comment/:id", async (req, res) => { + if (!req.session.sessionid) { + console.log("No session"); + } + const user = await userService.findUserByEmail(req.session.sessionid.email); + const data = { + content: req.body.content, + author: user._id + } + const articles = await articleService.createComment(req.params.id, data); + res.send(JSON.stringify(articles)); +}) + +router.delete("/comment/:articleid/:commentid", async (req, res) => { + if (!req.session.sessionid) { + console.log("No session"); + } + const articles = await articleService.deleteComment(req.params.articleid, req.params.commentid); + res.send(JSON.stringify(articles)); +}); + +router.put("/comment/like/:id", async (req, res) => { + if (!req.session.sessionid) { + console.log("No session"); + } + const user = await userService.findUserByEmail(req.session.sessionid.email); + const articles = await articleService.setLike(req.params.id, user._id) + res.send(JSON.stringify(articles)); +}); + export default router; diff --git a/frontend/src/components/Comment.js b/frontend/src/components/Comment.js index 872328bc0d738c059ffb74271181e11d71d8f05b..f200396a9a6573550864b9b2a1c0b60eed3f25fa 100644 --- a/frontend/src/components/Comment.js +++ b/frontend/src/components/Comment.js @@ -24,7 +24,7 @@ function Comments({data}) { function DeleteComment(e) { const data = {id: _id} axios - .delete(`http://localhost:8080/post/comment/${params.id}/${_id}`, data, + .delete(`http://localhost:8080/article/comment/${params.id}/${_id}`, data, { headers: {"Content-Type": 'application/json'} }) diff --git a/frontend/src/pages/PostRead.js b/frontend/src/pages/PostRead.js index 54dab046f44782054b8e4cbe4fe1444f44315aa6..2c48018b944bbf8cbf25f1b5fa00d6b0eba50b41 100644 --- a/frontend/src/pages/PostRead.js +++ b/frontend/src/pages/PostRead.js @@ -44,7 +44,7 @@ function PostRead() { }, []); function SetLike(){ - axios.put(`http://localhost:8080/post/comment/like/${params.id}`) + axios.put(`http://localhost:8080/article/comment/like/${params.id}`) .then(res => { alert("The comment is successfully uploaded"); return requestLoadArticleById(params.id) @@ -69,7 +69,7 @@ function PostRead() { return } const data = {content: inputComment} - axios.post(`http://localhost:8080/post/comment/${params.id}`, data, + axios.post(`http://localhost:8080/article/comment/${params.id}`, data, { headers: {"Content-Type": 'application/json'} }) @@ -124,7 +124,7 @@ function PostRead() { async function requestLoadArticleById(id) { const response = await axios({ - url: `http://localhost:8080/post/article/${id}`, // 통신할 웹문서 + url: `http://localhost:8080/article/${id}`, // 통신할 웹문서 method: 'get', // 통신할 방식 }); return response;