@DeleteMapping("/comment/{id}")
public ResponseEntity<String> deleteComment(@PathVariable Long id, HttpServletRequest req) {
User user = (User) req.getAttribute("user");
return commentService.deleteComment(id, user.getUsername(), user.getRole());
}
public ResponseEntity<String> deleteComment(Long id, String username, UserRoleEnum role) {
Comment comment = findComment(id);
if(role.getAuthority().equals("ROLE_ADMIN")|| comment.getUsername().equals(username))
commentRepository.delete(comment);
else
return ResponseEntity.ok("{\"msg\": \"댓글 삭제 실패\", \"statusCode\": 444}");
return ResponseEntity.ok("{\"msg\": \"댓글 삭제 성공\", \"statusCode\": 200}");
}
=>
Casecade로 게시판을 삭제시 관련 댓글 한번에 삭제, 댓글 삭제 시에는 댓글만 삭제