From 68749a7f6153bc24d0d673b7a3374e2d1df77e85 Mon Sep 17 00:00:00 2001 From: hsp9781 <> Date: Tue, 28 Mar 2023 10:05:46 +0900 Subject: [PATCH] =?UTF-8?q?[=EB=B0=95=ED=98=84=EC=84=9D]=20-=20=EC=95=84?= =?UTF-8?q?=EC=A7=81=20postBO=EC=97=90=EC=84=9C=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=B0=A9=EB=B2=95=EC=9D=84=20=EC=9E=98=20=EB=AA=A8=EB=A5=B4?= =?UTF-8?q?=EA=B2=A0=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hoicegram/common/FileManagerService.java | 3 +- .../post/comment/CommentRestController.java | 45 +++++++++++++++++++ .../hoicegram/post/comment/bo/CommentBO.java | 18 ++++++++ .../post/comment/dao/CommentDAO.java | 14 ++++++ .../hsp/hoicegram/post/model/PostDetail.java | 7 +++ src/main/resources/application.yml | 4 +- src/main/resources/mappers/commentMapper.xml | 33 ++++++++++++++ src/main/resources/mappers/likeMapper.xml | 10 +++++ src/main/webapp/WEB-INF/jsp/post/list.jsp | 2 +- 9 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/hsp/hoicegram/post/comment/CommentRestController.java create mode 100644 src/main/java/com/hsp/hoicegram/post/comment/bo/CommentBO.java create mode 100644 src/main/java/com/hsp/hoicegram/post/comment/dao/CommentDAO.java create mode 100644 src/main/resources/mappers/commentMapper.xml diff --git a/src/main/java/com/hsp/hoicegram/common/FileManagerService.java b/src/main/java/com/hsp/hoicegram/common/FileManagerService.java index b577ec5..63e3d67 100644 --- a/src/main/java/com/hsp/hoicegram/common/FileManagerService.java +++ b/src/main/java/com/hsp/hoicegram/common/FileManagerService.java @@ -10,10 +10,11 @@ public class FileManagerService { - public static final String FILE_UPLOAD_PATH = "D:\\web_hsp\\spring_project\\upload\\hoicegram\\images"; + public static final String FILE_UPLOAD_PATH = "/Users/hsp9781/web_hsp/spring_project/upload/hoicegram/images"; // "/Users/hsp9781/web_hsp/spring_project/upload/hoicegram/images" // "/Users/hsp9781/web_hsp/spring_project/upload/memo/images" + // "D:\\web_hsp\\spring_project\\upload\\hoicegram\\images" //파일 저장 -> 경로 생성 diff --git a/src/main/java/com/hsp/hoicegram/post/comment/CommentRestController.java b/src/main/java/com/hsp/hoicegram/post/comment/CommentRestController.java new file mode 100644 index 0000000..4006343 --- /dev/null +++ b/src/main/java/com/hsp/hoicegram/post/comment/CommentRestController.java @@ -0,0 +1,45 @@ +package com.hsp.hoicegram.post.comment; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpSession; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.hsp.hoicegram.post.comment.bo.CommentBO; + +@RestController +@RequestMapping("/post") +public class CommentRestController { + + @Autowired + private CommentBO commentBO; + + @PostMapping("/comment") + public Map addComment( + @RequestParam("text") String text + , @RequestParam("postId") int postId + , HttpSession session) { + + int userId = (Integer)session.getAttribute("userId"); + + int count = commentBO.addComment(userId, postId, text); + + Map resultMap = new HashMap<>(); + + if(count == 1) { + resultMap.put("result", "success"); + } else { + resultMap.put("result", "fail"); + } + + return resultMap; + + } + +} diff --git a/src/main/java/com/hsp/hoicegram/post/comment/bo/CommentBO.java b/src/main/java/com/hsp/hoicegram/post/comment/bo/CommentBO.java new file mode 100644 index 0000000..3f85b6d --- /dev/null +++ b/src/main/java/com/hsp/hoicegram/post/comment/bo/CommentBO.java @@ -0,0 +1,18 @@ +package com.hsp.hoicegram.post.comment.bo; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.hsp.hoicegram.post.comment.dao.CommentDAO; + +@Service +public class CommentBO { + + @Autowired + private CommentDAO commentDAO; + + public int addComment(int userId, int postId, String text) { + return commentDAO.insertComment(userId, postId, text); + } + +} diff --git a/src/main/java/com/hsp/hoicegram/post/comment/dao/CommentDAO.java b/src/main/java/com/hsp/hoicegram/post/comment/dao/CommentDAO.java new file mode 100644 index 0000000..24f2e48 --- /dev/null +++ b/src/main/java/com/hsp/hoicegram/post/comment/dao/CommentDAO.java @@ -0,0 +1,14 @@ +package com.hsp.hoicegram.post.comment.dao; + +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +@Repository +public interface CommentDAO { + + public int insertComment( + @Param("userId") int userId + , @Param("postId")int postId + , @Param("text") String text); + +} diff --git a/src/main/java/com/hsp/hoicegram/post/model/PostDetail.java b/src/main/java/com/hsp/hoicegram/post/model/PostDetail.java index d03303e..91dc3a6 100644 --- a/src/main/java/com/hsp/hoicegram/post/model/PostDetail.java +++ b/src/main/java/com/hsp/hoicegram/post/model/PostDetail.java @@ -7,6 +7,7 @@ public class PostDetail { private String nickname; private int likeCount; private boolean isLike; + private String comment; private String content; private String imagePath; @@ -14,6 +15,12 @@ public class PostDetail { + public String getComment() { + return comment; + } + public void setComment(String comment) { + this.comment = comment; + } public boolean isLike() { return isLike; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9943786..cbae0c0 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,6 +9,6 @@ spring: suffix: .jsp datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/hoicegram_0316 + url: jdbc:mysql://localhost:3306/hoicegram username: root - password: root \ No newline at end of file + password: hyunsuk2@ \ No newline at end of file diff --git a/src/main/resources/mappers/commentMapper.xml b/src/main/resources/mappers/commentMapper.xml new file mode 100644 index 0000000..c1ef256 --- /dev/null +++ b/src/main/resources/mappers/commentMapper.xml @@ -0,0 +1,33 @@ + + + + + + + + + INSERT INTO + `comment` + ( + `userId` + , `postId` + , `content` + , `createdAt` + , `updatedAt` + ) + VALUE + ( + #{userId} + , #{postId} + , #{text} + , now() + , now() + ) + + + + + + \ No newline at end of file diff --git a/src/main/resources/mappers/likeMapper.xml b/src/main/resources/mappers/likeMapper.xml index cc6b21d..7782384 100644 --- a/src/main/resources/mappers/likeMapper.xml +++ b/src/main/resources/mappers/likeMapper.xml @@ -23,6 +23,16 @@ ) + +