댓글 삭제 수정
This commit is contained in:
parent
799945e154
commit
3d03663896
@ -296,9 +296,10 @@ public class BoardController {
|
|||||||
@Member
|
@Member
|
||||||
@ParameterCheck
|
@ParameterCheck
|
||||||
@DeleteMapping("/comment/{commentId}")
|
@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();
|
MapDto map = new MapDto();
|
||||||
map.put("LOCCMTSEQ", commentId);
|
map.put("LOCCMTSEQ", commentId);
|
||||||
|
map.put("LOCCMTPNT", parentId);
|
||||||
|
|
||||||
boardService.deleteComment(map);
|
boardService.deleteComment(map);
|
||||||
return ApiResponse.ok("댓글이 삭제되었습니다.");
|
return ApiResponse.ok("댓글이 삭제되었습니다.");
|
||||||
|
|||||||
@ -66,13 +66,13 @@ public interface localbordMapper {
|
|||||||
void updateComment(MapDto map);
|
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);
|
String selectCommentPassword(int commentId);
|
||||||
|
|||||||
@ -173,17 +173,30 @@ public class localbordService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteComment(MapDto map) {
|
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) {
|
if (hasReplies) {
|
||||||
// 대댓글이 있는 경우, '삭제된 댓글입니다.'로 변경 (소프트 삭제)
|
// 대댓글이 있는 경우, '삭제된 댓글입니다.'로 변경 (소프트 삭제)
|
||||||
boardMapper.updateSoftDeleteComment(map);
|
boardMapper.updateSoftDeleteComment(commentId);
|
||||||
} else {
|
} else {
|
||||||
// 대댓글이 없는 경우, 완전 삭제
|
// 대댓글이 없는 경우, 완전 삭제
|
||||||
boardMapper.deleteComment(map);
|
boardMapper.deleteComment(commentId);
|
||||||
|
}
|
||||||
|
checkAndDeleteParentComment(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
public String selectCommentPassword(int commentId) {
|
||||||
|
|||||||
@ -207,7 +207,6 @@
|
|||||||
)
|
)
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
<!-- 댓글 삭제 (대댓글 없을 경우) -->
|
<!-- 댓글 삭제 (대댓글 없을 경우) -->
|
||||||
<delete id="deleteComment">
|
<delete id="deleteComment">
|
||||||
DELETE FROM localcomt
|
DELETE FROM localcomt
|
||||||
@ -217,9 +216,12 @@
|
|||||||
)
|
)
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<!-- 댓글에 대댓글이 있는지 확인 -->
|
<!-- 특정 댓글에 달린 대댓글 개수 조회 -->
|
||||||
<select id="selectHasReplies" resultType="int">
|
<select id="selectReplyCount" resultType="int">
|
||||||
SELECT COUNT(1) FROM localcomt WHERE LOCCMTPNT = #{LOCCMTSEQ}
|
SELECT COUNT(*)
|
||||||
|
FROM localcomt
|
||||||
|
WHERE LOCCMTPNT = #{LOCCMTSEQ}
|
||||||
|
AND LOCCMTPNT IS NOT NULL
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 댓글 비밀번호 조회 -->
|
<!-- 댓글 비밀번호 조회 -->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user