댓글 삭제 수정

This commit is contained in:
dyhj625 2025-03-11 10:33:37 +09:00
parent 799945e154
commit 3d03663896
4 changed files with 31 additions and 15 deletions

View File

@ -296,9 +296,10 @@ public class BoardController {
@Member
@ParameterCheck
@DeleteMapping("/comment/{commentId}")
public ApiResponse<String> deleteComment(@PathVariable("commentId") Long commentId) {
public ApiResponse<String> deleteComment(@PathVariable("commentId") Long commentId, @RequestParam(value = "LOCCMTPNT") Long parentId) {
MapDto map = new MapDto();
map.put("LOCCMTSEQ", commentId);
map.put("LOCCMTPNT", parentId);
boardService.deleteComment(map);
return ApiResponse.ok("댓글이 삭제되었습니다.");

View File

@ -66,13 +66,13 @@ public interface localbordMapper {
void updateComment(MapDto map);
// 댓글에 대댓글이 있는지 확인
int selectHasReplies(MapDto map);
int selectReplyCount(Long parentId);
// 댓글 내용만 삭제 처리 (대댓글 유지)
void updateSoftDeleteComment(MapDto map);
void updateSoftDeleteComment(Long commentId);
// 댓글 삭제 (대댓글 없음)
void deleteComment(MapDto map);
void deleteComment(Long commentId);
// 댓글 비밀번호 조회
String selectCommentPassword(int commentId);

View File

@ -173,20 +173,33 @@ public class localbordService {
}
public void deleteComment(MapDto map) {
Long commentId = (Long) map.get("LOCCMTSEQ");
// 댓글이 대댓글이 있는지 확인
boolean hasReplies = boardMapper.selectHasReplies(map) > 0;
boolean hasReplies = boardMapper.selectReplyCount(commentId) > 0;
if (hasReplies) {
// 대댓글이 있는 경우, '삭제된 댓글입니다.' 변경 (소프트 삭제)
boardMapper.updateSoftDeleteComment(map);
boardMapper.updateSoftDeleteComment(commentId);
} else {
// 대댓글이 없는 경우, 완전 삭제
boardMapper.deleteComment(map);
boardMapper.deleteComment(commentId);
}
checkAndDeleteParentComment(map);
}
public String selectCommentPassword(int commentId) {
private void checkAndDeleteParentComment(MapDto map) {
Long parentId = (Long) map.get("LOCCMTPNT");
if (parentId == null) return; // 부모가 없으면 종료
// 부모 댓글의 남아있는 대댓글 개수 확인
int remainingReplies = boardMapper.selectReplyCount(parentId);
if (remainingReplies == 0) {
// 남은 대댓글이 없으면 부모 댓글도 삭제
boardMapper.deleteComment(parentId);
}
}
public String selectCommentPassword(int commentId) {
return boardMapper.selectCommentPassword(commentId);
}

View File

@ -207,7 +207,6 @@
)
</update>
<!-- 댓글 삭제 (대댓글 없을 경우) -->
<delete id="deleteComment">
DELETE FROM localcomt
@ -217,9 +216,12 @@
)
</delete>
<!-- 댓글에 대댓글이 있는지 확인 -->
<select id="selectHasReplies" resultType="int">
SELECT COUNT(1) FROM localcomt WHERE LOCCMTPNT = #{LOCCMTSEQ}
<!-- 특정 댓글에 달린 대댓글 개수 조회 -->
<select id="selectReplyCount" resultType="int">
SELECT COUNT(*)
FROM localcomt
WHERE LOCCMTPNT = #{LOCCMTSEQ}
AND LOCCMTPNT IS NOT NULL
</select>
<!-- 댓글 비밀번호 조회 -->