Merge branch 'main' of http://192.168.0.251:3000/localnet/localhost-back.git into main
All checks were successful
LOCALNET-DEV/pipeline/head This commit looks good

This commit is contained in:
nevermoregb 2025-03-11 12:46:49 +09:00
commit f52b5be47c
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

@ -174,17 +174,30 @@ 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);
}
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) {

View File

@ -209,7 +209,6 @@
)
</update>
<!-- 댓글 삭제 (대댓글 없을 경우) -->
<delete id="deleteComment">
DELETE FROM localcomt
@ -219,9 +218,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>
<!-- 댓글 비밀번호 조회 -->