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
All checks were successful
LOCALNET-DEV/pipeline/head This commit looks good
This commit is contained in:
commit
f52b5be47c
@ -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("댓글이 삭제되었습니다.");
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -174,20 +174,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);
|
||||
}
|
||||
|
||||
|
||||
@ -209,7 +209,6 @@
|
||||
)
|
||||
</update>
|
||||
|
||||
|
||||
<!-- 댓글 삭제 (대댓글 없을 경우) -->
|
||||
<delete id="deleteComment">
|
||||
DELETE FROM localcomt
|
||||
@ -218,10 +217,13 @@
|
||||
SELECT 1 FROM localcomt WHERE LOCCMTPNT = #{LOCCMTSEQ}
|
||||
)
|
||||
</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>
|
||||
|
||||
<!-- 댓글 비밀번호 조회 -->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user