Skip to content

Commit

Permalink
HOTIFX: 삭제된 대댓글 다시 삭제할 수 없게 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
hyxklee committed Aug 26, 2024
1 parent 71291dd commit 3324484
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import leets.weeth.domain.comment.domain.service.CommentSaveService;
import leets.weeth.domain.user.domain.entity.User;
import leets.weeth.domain.user.domain.service.UserGetService;
import leets.weeth.global.common.error.exception.custom.CommentNotFoundException;
import leets.weeth.global.common.error.exception.custom.UserNotMatchException;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
Expand Down Expand Up @@ -81,6 +82,8 @@ public void deleteNoticeComment(Long commentId, Long userId) throws UserNotMatch
commentDeleteService.delete(parentComment.getId());
}
}
} else if (comment.getIsDeleted()) { // 삭제된 대댓글인 경우 예외
throw new CommentNotFoundException();
} else {
comment.markAsDeleted();
commentSaveService.save(comment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import leets.weeth.domain.comment.domain.service.CommentSaveService;
import leets.weeth.domain.user.domain.entity.User;
import leets.weeth.domain.user.domain.service.UserGetService;
import leets.weeth.global.common.error.exception.custom.CommentNotFoundException;
import leets.weeth.global.common.error.exception.custom.UserNotMatchException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -38,14 +39,14 @@ public void savePostComment(CommentDTO.Save dto, Long postId, Long userId) {
Post post = postFindService.find(postId);
Comment parentComment = null;

if(!(dto.parentCommentId() == null)) {
if (!(dto.parentCommentId() == null)) {
parentComment = commentFindService.find(dto.parentCommentId());
}
Comment comment = commentMapper.fromCommentDto(dto, post, user, parentComment);
commentSaveService.save(comment);

// 부모 댓글이 없다면 새 댓글로 추가
if(parentComment == null) {
if (parentComment == null) {
post.addComment(comment);
} else {
// 부모 댓글이 있다면 자녀 댓글로 추가
Expand Down Expand Up @@ -80,17 +81,19 @@ public void deletePostComment(Long commentId, Long userId) throws UserNotMatchEx
- child가 없는 댓글인 경우 -> 자식이 없기 떄문에 나만 삭제함
*/
// 현재 삭제하고자 하는 댓글이 자식이 없는 경우
if(comment.getChildren().isEmpty()){
if (comment.getChildren().isEmpty()) {
Comment parentComment = findParentComment(commentId);
commentDeleteService.delete(commentId);
if(parentComment != null){
if (parentComment != null) {
parentComment.getChildren().remove(comment);
if(parentComment.getIsDeleted() && parentComment.getChildren().isEmpty()){
if (parentComment.getIsDeleted() && parentComment.getChildren().isEmpty()) {
post.getComments().remove(parentComment);
commentDeleteService.delete(parentComment.getId());
}
}
} else{
} else if (comment.getIsDeleted()) { // 삭제된 대댓글인 경우 예외
throw new CommentNotFoundException();
} else {
comment.markAsDeleted();
commentSaveService.save(comment);
}
Expand Down

0 comments on commit 3324484

Please sign in to comment.