From b035424b182e2c11600a9df5b4df019cd8972f4a Mon Sep 17 00:00:00 2001
From: Kwangbin Hyun <bio8641@naver.com>
Date: Tue, 5 Dec 2023 13:08:07 +0900
Subject: [PATCH] WIP: comment methos changing

---
 backend/src/article/articleController.js | 30 ++++++++++++++++++++++++
 frontend/src/components/Comment.js       |  2 +-
 frontend/src/pages/PostRead.js           |  6 ++---
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/backend/src/article/articleController.js b/backend/src/article/articleController.js
index 921590e9..48ba723e 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 872328bc..f200396a 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 54dab046..2c48018b 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;
-- 
GitLab