-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 아직 postBO에서 처리 방법을 잘 모르겠음
- Loading branch information
hsp9781
committed
Mar 28, 2023
1 parent
07de31b
commit 68749a7
Showing
9 changed files
with
132 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/hsp/hoicegram/post/comment/CommentRestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
src/main/java/com/hsp/hoicegram/post/comment/bo/CommentBO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
src/main/java/com/hsp/hoicegram/post/comment/dao/CommentDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters