diff --git a/src/main/java/com/capstone/BnagFer/domain/board/controller/BoardController.java b/src/main/java/com/capstone/BnagFer/domain/board/controller/BoardController.java index 7246495f..abc68d6e 100644 --- a/src/main/java/com/capstone/BnagFer/domain/board/controller/BoardController.java +++ b/src/main/java/com/capstone/BnagFer/domain/board/controller/BoardController.java @@ -144,10 +144,11 @@ public ApiResponse updateComment(@PathVariable(name = "comme @Operation(summary = "게시글 댓글 삭제", description = "자신의 댓글을 삭제하는 기능. 댓글 작성자 만이 삭제 가능.") @DeleteMapping("/comment/{commentId}") - public ApiResponse deleteComment(@PathVariable(name = "commentId") Long commentId, @LoginUser User user) { + public ApiResponse deleteComment(@PathVariable(name = "commentId") Long commentId, @LoginUser User user) { boardService.deleteComment(commentId, user); - return ApiResponse.noContent(); + return ApiResponse.onSuccess("댓글이 삭제 되었습니다."); } + @Operation(summary = "자유게시판 사용자 차단", description = "차단을 하게되면, 차단한 사용자의 댓글, 게시글을 볼 수 없다.") @PostMapping("/block/{isBlockedUserId}") public ApiResponse blockUser(@LoginUser User user, @PathVariable(name = "isBlockedUserId") Long isBlockedUserId) { diff --git a/src/main/java/com/capstone/BnagFer/domain/board/dto/response/BoardDetailResponseDto.java b/src/main/java/com/capstone/BnagFer/domain/board/dto/response/BoardDetailResponseDto.java index 80977ba8..32bbec29 100644 --- a/src/main/java/com/capstone/BnagFer/domain/board/dto/response/BoardDetailResponseDto.java +++ b/src/main/java/com/capstone/BnagFer/domain/board/dto/response/BoardDetailResponseDto.java @@ -41,6 +41,7 @@ public record CommentList( Long userId, String nickName, String commentText, + boolean deleted, LocalDateTime createdAt, LocalDateTime updatedAt, List children @@ -52,6 +53,7 @@ public static CommentList from(Comment comment) { .boardId(comment.getBoard().getId()) .nickName(comment.getUser().getProfile().getNickname()) .commentText(comment.getCommentText()) + .deleted(comment.isDeleted()) .createdAt(comment.getCreatedAt()) .updatedAt(comment.getUpdatedAt()) .children(comment.getChildren().stream().map(CommentList::from).toList()) diff --git a/src/main/java/com/capstone/BnagFer/domain/board/entity/Comment.java b/src/main/java/com/capstone/BnagFer/domain/board/entity/Comment.java index f74e208a..b5239b28 100644 --- a/src/main/java/com/capstone/BnagFer/domain/board/entity/Comment.java +++ b/src/main/java/com/capstone/BnagFer/domain/board/entity/Comment.java @@ -4,6 +4,8 @@ import com.capstone.BnagFer.global.common.BaseEntity; import jakarta.persistence.*; import lombok.*; +import org.hibernate.annotations.ColumnDefault; + import java.util.ArrayList; import java.util.List; @@ -29,6 +31,10 @@ public class Comment extends BaseEntity { @Column(name = "comment_text", nullable = false) private String commentText; + @Column(name = "deleted") + @ColumnDefault("false") + private boolean deleted; // true면 삭제된 댓글 + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "parent_id") private Comment parent; @@ -49,4 +55,9 @@ public void setParent(Comment parent) { public void updateComment(UpdateCommentRequestDto request){ commentText = request.commentText(); } + + public void deleteComment() { + commentText = "삭제된 댓글 입니다."; + deleted = true; + } } diff --git a/src/main/java/com/capstone/BnagFer/domain/board/service/BoardService.java b/src/main/java/com/capstone/BnagFer/domain/board/service/BoardService.java index 15752972..feee41dc 100644 --- a/src/main/java/com/capstone/BnagFer/domain/board/service/BoardService.java +++ b/src/main/java/com/capstone/BnagFer/domain/board/service/BoardService.java @@ -190,16 +190,12 @@ public CommentResponseDto updateComment(Long commentId, UpdateCommentRequestDto } public void deleteComment(Long commentId, User user) { + Comment comment = boardCommentRepository.findById(commentId).orElseThrow(() -> new BoardExceptionHandler(ErrorCode.COMMENT_NOT_FOUND)); - long boardId = comment.getBoard().getId(); - long commentCount = redisUtil.boardGetCommentCount(boardId); - long childCnt = comment.getChildren().size(); if (!comment.getUser().getId().equals(user.getId())) { throw new BoardExceptionHandler(ErrorCode.USER_NOT_MATCHED); } - boardCommentRepository.deleteById(commentId); - commentCount -= (childCnt + 1L); - redisUtil.boardSaveCommentCount(boardId, commentCount); + comment.deleteComment(); } } diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java b/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java index f94a16b1..dd81fe41 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/controller/TacticController.java @@ -125,7 +125,7 @@ public ApiResponse updateComment(@PathVariable(name = "commentI @DeleteMapping("/comment/{commentId}") public ApiResponse deleteComment(@PathVariable(name = "commentId") Long commentId, @LoginUser User user){ tacticService.deleteComment(commentId, user); - return ApiResponse.noContent(); + return ApiResponse.onSuccess("댓글이 삭제 되었습니다."); } @Operation(summary = "전술 좋아요 & 좋아요 취소", description = "전술에 좋아요를 누르는 기능. 한번 더누르면 좋아요 취소.") diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/dto/TacticDetailResponse.java b/src/main/java/com/capstone/BnagFer/domain/tactic/dto/TacticDetailResponse.java index 00816777..21a85cf8 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/dto/TacticDetailResponse.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/dto/TacticDetailResponse.java @@ -70,6 +70,7 @@ public record CommentList( Long userId, String nickname, String comment, + boolean deleted, LocalDateTime createdAt, LocalDateTime updateAt, List children @@ -81,6 +82,7 @@ public static CommentList from(TacticComment comment){ .userId(comment.getUser().getId()) .nickname(comment.getUser().getProfile().getNickname()) .comment(comment.getComment()) + .deleted(comment.isDeleted()) .createdAt(comment.getCreatedAt()) .updateAt(comment.getUpdatedAt()) .children(comment.getChildren().stream().map(CommentList::from).toList()) diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/entity/TacticComment.java b/src/main/java/com/capstone/BnagFer/domain/tactic/entity/TacticComment.java index 87b539ba..0a322e28 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/entity/TacticComment.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/entity/TacticComment.java @@ -5,6 +5,7 @@ import com.capstone.BnagFer.global.common.BaseEntity; import jakarta.persistence.*; import lombok.*; +import org.hibernate.annotations.ColumnDefault; import java.util.ArrayList; import java.util.List; @@ -31,6 +32,10 @@ public class TacticComment extends BaseEntity { @Column(name = "comment", nullable = false) private String comment; + @Column(name = "deleted") + @ColumnDefault("false") + private boolean deleted; // true면 삭제된 댓글 + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "parent_id") private TacticComment parent; @@ -51,4 +56,9 @@ public void setParent(TacticComment parent) { public void updateComment(CommentUpdateRequest request){ comment = request.comment(); } + + public void deleteComment() { + comment = "삭제된 댓글 입니다."; + deleted = true; + } } diff --git a/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticService.java b/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticService.java index 8cb957d9..dee8e613 100644 --- a/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticService.java +++ b/src/main/java/com/capstone/BnagFer/domain/tactic/service/TacticService.java @@ -145,18 +145,9 @@ public CommentResponse updateComment(Long commentId, CommentUpdateRequest reques public void deleteComment(Long commentId, User user) { TacticComment tacticComment = commentRepository.findById(commentId).orElseThrow(() -> new TacticExceptionHandler(ErrorCode.COMMENT_NOT_FOUND)); - - long tacticId = tacticComment.getTactic().getTacticId(); - - long commentCount = redisUtil.getCommentCount(tacticId); - long chlidCnt = tacticComment.getChildren().size(); - if (!tacticComment.getUser().getId().equals(user.getId())) throw new TacticExceptionHandler(ErrorCode.USER_NOT_MATCHED); - - commentRepository.deleteById(commentId); - commentCount -= (chlidCnt + 1L); - redisUtil.saveCommentCount(tacticId, commentCount); + tacticComment.deleteComment(); } public ApiResponse likeButton(Long tacticId, User user) {