Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
//글 관련 응답
COMMUNITY_NOT_FOUND(HttpStatus.NOT_FOUND,"COMMUNITY4001","글을 찾을 수 없습니다"),
COMMUNITY_NOT_OWNER(HttpStatus.NOT_ACCEPTABLE,"COMMUNITY4002","해당 글의 소유자가 아닙니다."),
COMMUNITY_COMMENT_NOT_OWNER(HttpStatus.NOT_ACCEPTABLE,"COMMUNITY4003","해당 댓글의 소유자가 아닙니다."),
COMMUNITY_COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND,"COMMUNITY4004","댓글을 찾을수 없습니다."),

//언어 관련 응답
LANGUAGE_NOT_EXIST(HttpStatus.NOT_FOUND, "LANGUAGE4001", "해당 언어가 없습니다.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

public interface CommentService {
public CommentResponseDTO.commentCreateRes createComment(String userId, Long communityId, CommentRequestDTO.commentCreateReq requestBody);
public CommentResponseDTO.commentDeleteRes deleteComment(String userId, Long communityId, Long commentId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@ public CommentResponseDTO.commentCreateRes createComment(String userId, Long com

return new CommentResponseDTO.commentCreateRes(savedComment.getId());
}

@Override
public CommentResponseDTO.commentDeleteRes deleteComment(String userId, Long communityId, Long commentId) {
User user = userRepository.findByEmail(userId)
.orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));
Community community = communityRepository.findById(communityId)
.orElseThrow(() -> new GeneralException(ErrorStatus.COMMUNITY_NOT_FOUND));
Comment comment = commentRepository.findById(commentId).orElseThrow(() -> new GeneralException(ErrorStatus.COMMUNITY_COMMENT_NOT_FOUND));
if(!comment.getUser().equals(user)) {
throw new GeneralException(ErrorStatus.COMMUNITY_COMMENT_NOT_OWNER);
}
commentRepository.deleteById(commentId);
return new CommentResponseDTO.commentDeleteRes(commentId, communityId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,25 @@ public ApiResponse<CommunityResponseDTO.ModifyPostDTO> modifyCommunity(@RequestH
String gmail = jwtTokenProvider.getGoogleEmail(accessToken);
return ApiResponse.onSuccess(communityService.modifyCommunityPost(gmail, communityId, modifyPostDTO));
}

@DeleteMapping(value = "/{community_id}/{comment_id}/comment/delete")
@Operation(summary = "커뮤니티 댓글 삭제 API", description = "커뮤니티 게시판에 댓글을 삭제 API입니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER4001", description = "사용자를 찾을수 없습니다.")
})
@Parameters({
@Parameter(name = "Authorization", description = "RequestHeader - 로그인한 사용자 토큰"),
@Parameter(name = "community_id", description = "PathVariable - 게시글 아이디"),
@Parameter(name = "comment_id", description = "PathVariable - 게시글 댓글 아이디"),
})
public ApiResponse<CommentResponseDTO.commentDeleteRes> deleteComment(@RequestHeader(name = "Authorization") String accessToken,
@PathVariable(name = "community_id") Long communityId,
@PathVariable(name = "comment_id") Long commentId) {
{
String gmail = jwtTokenProvider.getGoogleEmail(accessToken);
return ApiResponse.onSuccess(commentService.deleteComment(gmail, communityId, commentId));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ public static class commentCreateRes{
Long commentId;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class commentDeleteRes{
Long commentId;
Long communityId;
}

}
Loading