Skip to content

Commit

Permalink
[박현석]
Browse files Browse the repository at this point in the history
- 아직 postBO에서 처리 방법을 잘 모르겠음
  • Loading branch information
hsp9781 committed Mar 28, 2023
1 parent 07de31b commit 68749a7
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"

//파일 저장 -> 경로 생성

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> resultMap = new HashMap<>();

if(count == 1) {
resultMap.put("result", "success");
} else {
resultMap.put("result", "fail");
}

return resultMap;

}

}
18 changes: 18 additions & 0 deletions src/main/java/com/hsp/hoicegram/post/comment/bo/CommentBO.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
14 changes: 14 additions & 0 deletions src/main/java/com/hsp/hoicegram/post/comment/dao/CommentDAO.java
Original file line number Diff line number Diff line change
@@ -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);

}
7 changes: 7 additions & 0 deletions src/main/java/com/hsp/hoicegram/post/model/PostDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ public class PostDetail {
private String nickname;
private int likeCount;
private boolean isLike;
private String comment;
private String content;
private String imagePath;





public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public boolean isLike() {
return isLike;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
password: hyunsuk2@
33 changes: 33 additions & 0 deletions src/main/resources/mappers/commentMapper.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">


<mapper namespace="com.hsp.hoicegram.post.comment.dao.CommentDAO">

<insert id="insertComment" parameterType="map">
INSERT INTO
`comment`
(
`userId`
, `postId`
, `content`
, `createdAt`
, `updatedAt`
)
VALUE
(
#{userId}
, #{postId}
, #{text}
, now()
, now()
)


</insert>


</mapper>
10 changes: 10 additions & 0 deletions src/main/resources/mappers/likeMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
)
</insert>

<select id="selectLikeCount" parameterType="int" resultType="int">
SELECT
count(1)
FROM
`like`
WHERE
`postId` = #{postId}

</select>

<select id="selectCountLikeByUserId" parameterType="map" resultType="int">
SELECT
count(*)
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/jsp/post/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</div>
<div class="like d-flex align-items-center ml-1">
<c:choose>
<c:when test="${post.Like }">
<c:when test="${post.like }">
<i class="bi bi-heart-fill"></i>
</c:when>
<c:otherwise>
Expand Down

0 comments on commit 68749a7

Please sign in to comment.