From a2e12f16c9c57919e52e0109a9f9947c9de3b6af Mon Sep 17 00:00:00 2001 From: dhkstnaos Date: Thu, 17 Nov 2022 21:56:19 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=EB=A5=BC=20=EC=88=98=EC=A0=95=ED=95=98?= =?UTF-8?q?=EB=9D=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/developer/wiki/common/ExceptionAdvice.java | 9 +-------- .../application/comment/CommentPasswordCheckService.java | 7 +++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/developer/wiki/common/ExceptionAdvice.java b/src/main/java/com/developer/wiki/common/ExceptionAdvice.java index ede2c61..daf670d 100644 --- a/src/main/java/com/developer/wiki/common/ExceptionAdvice.java +++ b/src/main/java/com/developer/wiki/common/ExceptionAdvice.java @@ -38,13 +38,6 @@ public ErrorResponse handleConflictException(ConflictException e) { return new ErrorResponse(List.of(e.getMessage())); } - @ResponseBody - @ResponseStatus(HttpStatus.UNAUTHORIZED) - @ExceptionHandler(UnAuthorizedException.class) - public ErrorResponse unAuthorizedException(UnAuthorizedException e) { - return new ErrorResponse(List.of(e.getMessage())); - } - @ResponseBody @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(value = {BindException.class}) @@ -62,7 +55,7 @@ public ErrorResponse missingServletRequestParameterException(ServletRequestBindi } @ResponseBody - @ResponseStatus(HttpStatus.FORBIDDEN) + @ResponseStatus(HttpStatus.UNAUTHORIZED) @ExceptionHandler(UnAuthorizedException.class) public ErrorResponse handleNotMatchPasswordException(UnAuthorizedException e) { return new ErrorResponse(List.of(e.getMessage())); diff --git a/src/main/java/com/developer/wiki/question/command/application/comment/CommentPasswordCheckService.java b/src/main/java/com/developer/wiki/question/command/application/comment/CommentPasswordCheckService.java index b02a1c7..6dcfe33 100644 --- a/src/main/java/com/developer/wiki/question/command/application/comment/CommentPasswordCheckService.java +++ b/src/main/java/com/developer/wiki/question/command/application/comment/CommentPasswordCheckService.java @@ -1,5 +1,6 @@ package com.developer.wiki.question.command.application.comment; +import com.developer.wiki.common.exception.UnAuthorizedException; import com.developer.wiki.question.command.application.dto.PasswordRequest; import com.developer.wiki.question.command.domain.Comment; import com.developer.wiki.question.command.domain.CommentRepository; @@ -18,8 +19,10 @@ public class CommentPasswordCheckService { public boolean checkPassword(Long id, PasswordRequest passwordRequest, Long userId) { Comment comment = commentRepository.findById(id).orElseThrow(EntityNotFoundException::new); - if (Objects.isNull(userId) || userId.equals(comment.getUserId())) { - return comment.checkPassword(passwordRequest.getPassword()); + //Null이 아니면서, id도 맞지 않을때 + if (!Objects.isNull(userId) && !userId.equals(comment.getUserId())) { + throw new UnAuthorizedException("수정 권한이 없습니다."); } + return comment.checkPassword(passwordRequest.getPassword()); } }