diff --git a/src/main/java/com/palnet/board/app/jh/controller/JunheeReplyRestController.java b/src/main/java/com/palnet/board/app/jh/controller/JunheeReplyRestController.java index 65c0532..4d57a5a 100644 --- a/src/main/java/com/palnet/board/app/jh/controller/JunheeReplyRestController.java +++ b/src/main/java/com/palnet/board/app/jh/controller/JunheeReplyRestController.java @@ -8,10 +8,13 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.palnet.board.app.jh.dto.JunheeReplyDto; +import com.palnet.board.app.jh.dto.JunheeRequestBoard; +import com.palnet.board.app.jh.dto.JunheeRequestReply; import com.palnet.board.app.jh.dto.JunheeResponseReply; import com.palnet.board.app.jh.service.JunheeReplyService; @@ -33,4 +36,19 @@ public class JunheeReplyRestController { return ResponseEntity.status(HttpStatus.OK).body(responseReply); } + @PostMapping("/commentWrite") + public ResponseEntity writeCommnet(JunheeRequestReply requestReply) throws Exception { + int result = ReplyService.writeCommnet(requestReply); + + return ResponseEntity.status(HttpStatus.OK).body(result); + } + + @PostMapping("/replyWrite") + public ResponseEntity writeReply(JunheeRequestReply requestReply) throws Exception { + int result = ReplyService.writeReply(requestReply); + + return ResponseEntity.status(HttpStatus.OK).body(result); + } + + } diff --git a/src/main/java/com/palnet/board/app/jh/dto/JunheeRequestReply.java b/src/main/java/com/palnet/board/app/jh/dto/JunheeRequestReply.java new file mode 100644 index 0000000..4219a7f --- /dev/null +++ b/src/main/java/com/palnet/board/app/jh/dto/JunheeRequestReply.java @@ -0,0 +1,16 @@ +package com.palnet.board.app.jh.dto; + +import lombok.Data; +import org.apache.ibatis.type.Alias; + +@Data +public class JunheeRequestReply { + /*댓글 작성(insert)시 사용 */ + int id; + int boardId; + int targetId; + String content; + String regUser; + String regDtm; + +} diff --git a/src/main/java/com/palnet/board/app/jh/mapper/JunheeBoardMapper.xml b/src/main/java/com/palnet/board/app/jh/mapper/JunheeBoardMapper.xml index f06d80c..85eed23 100644 --- a/src/main/java/com/palnet/board/app/jh/mapper/JunheeBoardMapper.xml +++ b/src/main/java/com/palnet/board/app/jh/mapper/JunheeBoardMapper.xml @@ -68,7 +68,6 @@ REG_USER, REG_DTM, UPD_USER - FROM TB_COM_BOARD LIMIT #{endNum} OFFSET #{startNum} @@ -79,24 +78,6 @@ FROM TB_COM_BOARD - - + + + INSERT INTO TB_COM_COMMENT( + ID, + BOARD_ID, + TARGET_ID, + CONTENT, + REG_USER, + REG_DATE + ) VALUES ( + null, + #{boardId}, + null, + #{content}, + #{regUser}, + SYSDATE() + ) + + + + + + INSERT INTO TB_COM_COMMENT( + ID, + BOARD_ID, + TARGET_ID, + CONTENT, + REG_USER, + REG_DATE + ) VALUES ( + null, + #{boardId}, + #{targetId}, + #{content}, + #{regUser}, + SYSDATE() + ) + + \ No newline at end of file diff --git a/src/main/java/com/palnet/board/app/jh/service/JunheeReplyService.java b/src/main/java/com/palnet/board/app/jh/service/JunheeReplyService.java index 18ec430..bd65a56 100644 --- a/src/main/java/com/palnet/board/app/jh/service/JunheeReplyService.java +++ b/src/main/java/com/palnet/board/app/jh/service/JunheeReplyService.java @@ -3,10 +3,15 @@ package com.palnet.board.app.jh.service; import java.util.List; import com.palnet.board.app.jh.dto.JunheeReplyDto; +import com.palnet.board.app.jh.dto.JunheeRequestReply; import com.palnet.board.app.jh.dto.JunheeResponseReply; public interface JunheeReplyService { List viewReply(int boardId) throws Exception; + int writeCommnet(JunheeRequestReply requestReply) throws Exception; + + int writeReply(JunheeRequestReply requestReply) throws Exception; + } diff --git a/src/main/java/com/palnet/board/app/jh/service/JunheeReplyServiceImpl.java b/src/main/java/com/palnet/board/app/jh/service/JunheeReplyServiceImpl.java index 023bf47..6609e3b 100644 --- a/src/main/java/com/palnet/board/app/jh/service/JunheeReplyServiceImpl.java +++ b/src/main/java/com/palnet/board/app/jh/service/JunheeReplyServiceImpl.java @@ -8,6 +8,7 @@ import org.modelmapper.ModelMapper; import org.springframework.stereotype.Service; import com.palnet.board.app.jh.dto.JunheeReplyDto; +import com.palnet.board.app.jh.dto.JunheeRequestReply; import com.palnet.board.app.jh.dto.JunheeResponseReply; import com.palnet.board.app.jh.mapper.JunheeReplyMapper; @@ -40,4 +41,24 @@ public class JunheeReplyServiceImpl implements JunheeReplyService { return responseReply; } + + @Override + public int writeCommnet(JunheeRequestReply requestReply) throws Exception { + int regUser = ReplyMapper.anonymousCount(requestReply.getBoardId()) + 1; + requestReply.setRegUser("익명" + regUser); + + int result = ReplyMapper.writeCommnet(requestReply); + return result; + } + + @Override + public int writeReply(JunheeRequestReply requestReply) throws Exception { + int regUser = ReplyMapper.anonymousCount(requestReply.getBoardId()) + 1; + requestReply.setRegUser("익명" + regUser); + + int result = ReplyMapper.writeReply(requestReply); + return result; + } + + } diff --git a/src/main/webapp/WEB-INF/view/jh/board/detailView.jsp b/src/main/webapp/WEB-INF/view/jh/board/detailView.jsp index 1074913..8fb06cf 100644 --- a/src/main/webapp/WEB-INF/view/jh/board/detailView.jsp +++ b/src/main/webapp/WEB-INF/view/jh/board/detailView.jsp @@ -62,8 +62,8 @@
- - + +
@@ -186,48 +181,123 @@ success: function(response) { console.log(response) - /* comment */ + /* comment (each를 역으로 가져와서 idx는 거꾸로.. 엉망)*/ $($(response).get().reverse()).each( function(i, item) { if(item.targetId==0) { var comment = - "
" + + "
" + "" + "" + item.regUser + "" + "" + item.regDate + "" + - "답글" + + "답글" + + "" + "" + - "" + item.content + "" + + "" + item.content + "" + "
" $(".comment-input").after(comment) - - /* reply */ - $.each(item.targetReplys, function(idx, it) { - /* onclick으로 답글다는곳 나타나면 걔는 $('.reply-box').prepend(머시기) 하면 될듯 */ - var rb = $("
"); - $(".comment-view").append(rb); - - var reply = - "
" + - "" + - "" + it.regUser + "" + - "" + it.regDate + "" + - "" + - "" + it.content + "" + - "
" - - $('#user' + (i+1)).append(reply) - }) + + var rb = $("
"); + $(".comment-view").append(rb); + + /* reply */ + $.each(item.targetReplys, function(idx, it) { + var reply = + "
" + + "" + + "" + it.regUser + "" + + "" + it.regDate + "" + + "" + + "" + it.content + "" + + "
" + + $('#reply-box' + (i+1)).append(reply) + }) } }) - /* 댓글 개수 */ var count = response.length $('.total').text('댓글 ' + count); } }) } + + + /* 답글 클릭시 답글 입력창 생성 */ + function replyInputCreate(index, id) { + var chk = document.querySelector("input[name=replyCheck" + index + "]").checked; + + if(chk) { + document.querySelector("input[name=replyCheck" + index + "]").checked = false; + $('.reply-input').remove(); + } else { + document.querySelector("input[name=replyCheck" + index + "]").checked = true; + var replyInput = + "
" + + "" + + "" + + ""+ + "
" + $('#reply-box' + index).before(replyInput) + } + } + + + /* comment 작성 */ + $(document).on("click", "#cmtSave", function() { + var boardNum = '<%=boardId%>'; + + var boardId = boardNum; + var content = $('.comment-input').find('textarea[id="cmtContent"]').val(); + + var obj = { + boardId: boardId, + content: content + } + + $.ajax({ + url: "/api/jh/reply/commentWrite", + type: "POST", + data: obj, + dataType: 'JSON', + success: function(res) { + if(res == '1') { + alert("등록 성공") + location.href="/view/jh/board/detailView/" + boardNum + } + } + }) + }) + + /* reply 작성 */ + $(document).on("click", "#replySave", function() { + var boardNum = '<%=boardId%>'; + + var boardId = boardNum; + var targetId = $('.reply-input').find('span[id="targetNum"]').text(); + var content = $('.reply-input').find('textarea[id="replyContent"]').val(); + + var obj = { + boardId: boardId, + targetId: targetId, + content: content + } + + $.ajax({ + url: "/api/jh/reply/replyWrite", + type: "POST", + data: obj, + dataType: 'JSON', + success: function(res) { + if(res == '1') { + alert("등록 성공") + location.href="/view/jh/board/detailView/" + boardNum + } + } + }) + }) + /* 글 삭제 */ $(document).on("click", "#delete", function() { diff --git a/src/main/webapp/WEB-INF/view/jh/board/write.jsp b/src/main/webapp/WEB-INF/view/jh/board/write.jsp index 22835db..498b133 100644 --- a/src/main/webapp/WEB-INF/view/jh/board/write.jsp +++ b/src/main/webapp/WEB-INF/view/jh/board/write.jsp @@ -71,25 +71,9 @@