Skip to content

Commit

Permalink
Merge pull request #78 from Team-Shaka/feat/71
Browse files Browse the repository at this point in the history
Feat/71 댓글 작성, 삭제 관련 예외 처리 추가
  • Loading branch information
HyoBN authored Jul 10, 2024
2 parents 599232c + 4ba711f commit 2ac9857
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ public CommentResponseDTO.CommentIdResponseDto createComment(User user, Long tre

public CommentResponseDTO.CommentIdResponseDto createReply(User user, Long treehouseId, Long postId, Long parentId, CommentRequestDTO.createComment request){

if(commentQueryAdapter.getCommentById(parentId).getParentId()!=-1L){
throw new CommentException(GlobalErrorCode.REPLY_CREATE_BAD_REQUEST);
}
TreeHouse treehouse = treehouseQueryAdapter.getTreehouseById(treehouseId);
Post post = postQueryAdapter.findById(postId);
Member writer = memberQueryAdapter.findByUserAndTreehouse(user, treehouse);
Expand All @@ -181,8 +184,13 @@ public CommentResponseDTO.CommentIdResponseDto createReply(User user, Long treeh
public void deleteComment(User user, Long treehouseId, Long postId, Long commentId) {

Comment comment = commentQueryAdapter.getCommentById(commentId);
Member loginMember = memberQueryAdapter.findByUserAndTreehouse(user, treehouseQueryAdapter.getTreehouseById(treehouseId));
Member commentWriter = commentQueryAdapter.getCommentById(commentId).getWriter();
Member postWriter = postQueryAdapter.findById(postId).getWriter();

commentCommandAdapter.deleteComment(comment);
if (loginMember.getId() == commentWriter.getId() || loginMember.getId() == postWriter.getId()) {
commentCommandAdapter.deleteComment(comment);
} else throw new CommentException(GlobalErrorCode.COMMENT_DELETE_FORBIDDEN);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public CommonResponse deleteComment(
@AuthMember @Parameter(hidden = true) User user
)
{
commentService.deleteComment(user,commentId,treehouseId,postId);
commentService.deleteComment(user,treehouseId,postId, commentId);
return CommonResponse.onSuccess(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ public enum GlobalErrorCode implements BaseErrorCode{
// POST + 404 Not Found - 찾을 수 없음
POST_NOT_FOUND(NOT_FOUND, "POST404_1", "존재하지 않는 게시글입니다."),

// COMMENT + 403 Forbidden - 금지됨
COMMENT_SELF_REPORT(FORBIDDEN, "COMMENT403_1", "자신의 댓글은 신고할 수 없습니다."),

// COMMENT + 403 Forbidden
COMMENT_DELETE_FORBIDDEN(FORBIDDEN, "COMMENT403_2", "자신이 작성한 게시글에 대한 댓글이나 자신이 작성한 댓글만 삭제 가능합니다."),

// COMMENT + 404 Not Found - 찾을 수 없음
COMMENT_NOT_FOUND(NOT_FOUND, "COMMENT404_1", "존재하지 않는 댓글입니다."),

// COMMENT + 403 Forbidden - 금지됨
COMMENT_SELF_REPORT(FORBIDDEN, "COMMENT403_1", "자신의 댓글은 신고할 수 없습니다."),
// REPLY + 400 Bad Request - 잘못된 요청
REPLY_CREATE_BAD_REQUEST(BAD_REQUEST, "REPLY400_1", "댓글에 대해서만 대댓글 작성 가능합니다."),

// REPLY + 404 Not Found - 찾을 수 없음
REPLY_NOT_FOUND(NOT_FOUND, "REPLY404_1", "존재하지 않는 답글입니다."),
Expand Down

0 comments on commit 2ac9857

Please sign in to comment.