diff --git a/backend/src/main/java/site/coduo/retrospect/controller/RetrospectController.java b/backend/src/main/java/site/coduo/retrospect/controller/RetrospectController.java index 008339f2..7cebcbf3 100644 --- a/backend/src/main/java/site/coduo/retrospect/controller/RetrospectController.java +++ b/backend/src/main/java/site/coduo/retrospect/controller/RetrospectController.java @@ -39,7 +39,8 @@ public ResponseEntity createRetrospect( @GetMapping("/retrospects") public ResponseEntity findRetrospects( - @CookieValue(SIGN_IN_COOKIE_NAME) final String credentialToken) { + @CookieValue(SIGN_IN_COOKIE_NAME) final String credentialToken + ) { final FindRetrospectsResponse response = retrospectService.findAllRetrospectsByMember(credentialToken); return ResponseEntity.ok(response); } @@ -47,7 +48,8 @@ public ResponseEntity findRetrospects( @GetMapping("/retrospects/{accessCode}") public ResponseEntity getRetrospect( @CookieValue(SIGN_IN_COOKIE_NAME) final String credentialToken, - @PathVariable("accessCode") final String accessCode) { + @PathVariable("accessCode") final String accessCode + ) { final Retrospect retrospect = retrospectService.findRetrospectByAccessCode(credentialToken, accessCode); final FindRetrospectByIdResponse response = FindRetrospectByIdResponse.from(retrospect); return ResponseEntity.ok(response); diff --git a/backend/src/main/java/site/coduo/retrospect/controller/RetrospectExceptionHandler.java b/backend/src/main/java/site/coduo/retrospect/controller/RetrospectExceptionHandler.java index d9c9d58d..4cd37f9e 100644 --- a/backend/src/main/java/site/coduo/retrospect/controller/RetrospectExceptionHandler.java +++ b/backend/src/main/java/site/coduo/retrospect/controller/RetrospectExceptionHandler.java @@ -9,10 +9,12 @@ import lombok.extern.slf4j.Slf4j; import site.coduo.common.controller.response.ApiErrorResponse; import site.coduo.retrospect.controller.error.RetrospectApiError; +import site.coduo.retrospect.exception.DuplicateRetrospectException; import site.coduo.retrospect.exception.InvalidRetrospectContentException; import site.coduo.retrospect.exception.InvalidRetrospectInputValueException; import site.coduo.retrospect.exception.InvalidRetrospectQuestionTypeException; import site.coduo.retrospect.exception.NotRetrospectOwnerAccessException; +import site.coduo.retrospect.exception.RetrospectException; import site.coduo.retrospect.exception.RetrospectNotFoundException; @Slf4j @@ -47,6 +49,14 @@ public ResponseEntity handleInvalidRetrospectQuestionTypeExcep .body(new ApiErrorResponse(RetrospectApiError.INVALID_RETROSPECT_QUESTION_TYPE_ERROR.getMessage())); } + @ExceptionHandler(DuplicateRetrospectException.class) + public ResponseEntity handleDuplicateRetrospectException(final DuplicateRetrospectException e) { + log.warn(e.getMessage()); + + return ResponseEntity.status(RetrospectApiError.DUPLICATE_RETROSPECT_ERROR.getHttpStatus()) + .body(new ApiErrorResponse(RetrospectApiError.DUPLICATE_RETROSPECT_ERROR.getMessage())); + } + @ExceptionHandler(NotRetrospectOwnerAccessException.class) public ResponseEntity handleNotRetrospectOwnerAccessException( final NotRetrospectOwnerAccessException e) { @@ -64,4 +74,12 @@ public ResponseEntity handleRetrospectNotFoundException( return ResponseEntity.status(RetrospectApiError.RETROSPECT_NOT_FOUND_ERROR.getHttpStatus()) .body(new ApiErrorResponse(RetrospectApiError.RETROSPECT_NOT_FOUND_ERROR.getMessage())); } + + @ExceptionHandler(RetrospectException.class) + public ResponseEntity handleRetrospectException(final RetrospectException e) { + log.warn(e.getMessage()); + + return ResponseEntity.status(RetrospectApiError.INVALID_RETROSPECT_REQUEST_ERROR.getHttpStatus()) + .body(new ApiErrorResponse(RetrospectApiError.INVALID_RETROSPECT_REQUEST_ERROR.getMessage())); + } } diff --git a/backend/src/main/java/site/coduo/retrospect/controller/error/RetrospectApiError.java b/backend/src/main/java/site/coduo/retrospect/controller/error/RetrospectApiError.java index 9fe24ab5..d7e070cf 100644 --- a/backend/src/main/java/site/coduo/retrospect/controller/error/RetrospectApiError.java +++ b/backend/src/main/java/site/coduo/retrospect/controller/error/RetrospectApiError.java @@ -9,12 +9,13 @@ @RequiredArgsConstructor public enum RetrospectApiError { + INVALID_RETROSPECT_REQUEST_ERROR(HttpStatus.BAD_REQUEST, "유효하지 않은 회고 요청입니다."), INVALID_RETROSPECT_CONTENT_ERROR(HttpStatus.BAD_REQUEST, "잘못된 회고 내용입니다."), INVALID_RETROSPECT_QUESTION_TYPE_ERROR(HttpStatus.BAD_REQUEST, "잘못된 회고 질문 유형입니다."), INVALID_RETROSPECT_INPUT_ERROR(HttpStatus.BAD_REQUEST, "잘못된 회고 입력 값입니다."), NOT_RETROSPECT_OWNER_ACCESS_ERROR(HttpStatus.FORBIDDEN, "회고 소유자 외 접근할 수 없는 작업입니다."), RETROSPECT_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "해당 요청의 회고가 존재하지 않습니다."), - MAX_RETROSPECT_LIMIT_REACHED_ERROR(HttpStatus.BAD_REQUEST, "회고는 최대 6개까지 추가할 수 있습니다."), + DUPLICATE_RETROSPECT_ERROR(HttpStatus.BAD_REQUEST, "이미 회고가 작성되었습니다."), ; private final HttpStatus httpStatus; diff --git a/backend/src/main/java/site/coduo/retrospect/exception/DuplicateRetrospectException.java b/backend/src/main/java/site/coduo/retrospect/exception/DuplicateRetrospectException.java new file mode 100644 index 00000000..f97a2dcf --- /dev/null +++ b/backend/src/main/java/site/coduo/retrospect/exception/DuplicateRetrospectException.java @@ -0,0 +1,8 @@ +package site.coduo.retrospect.exception; + +public class DuplicateRetrospectException extends RetrospectException { + + public DuplicateRetrospectException(final String message) { + super(message); + } +} diff --git a/backend/src/main/java/site/coduo/retrospect/exception/MaxRetrospectLimitException.java b/backend/src/main/java/site/coduo/retrospect/exception/MaxRetrospectLimitException.java deleted file mode 100644 index 581bcb1f..00000000 --- a/backend/src/main/java/site/coduo/retrospect/exception/MaxRetrospectLimitException.java +++ /dev/null @@ -1,12 +0,0 @@ -package site.coduo.retrospect.exception; - -public class MaxRetrospectLimitException extends RetrospectException { - - public MaxRetrospectLimitException(final String message) { - super(message); - } - - public MaxRetrospectLimitException(final String message, final Throwable cause) { - super(message, cause); - } -} diff --git a/backend/src/main/java/site/coduo/retrospect/service/RetrospectService.java b/backend/src/main/java/site/coduo/retrospect/service/RetrospectService.java index 405ffb63..dae98b2a 100644 --- a/backend/src/main/java/site/coduo/retrospect/service/RetrospectService.java +++ b/backend/src/main/java/site/coduo/retrospect/service/RetrospectService.java @@ -18,7 +18,7 @@ import site.coduo.retrospect.domain.Retrospect; import site.coduo.retrospect.domain.RetrospectContent; import site.coduo.retrospect.domain.RetrospectContents; -import site.coduo.retrospect.exception.MaxRetrospectLimitException; +import site.coduo.retrospect.exception.DuplicateRetrospectException; import site.coduo.retrospect.exception.NotRetrospectOwnerAccessException; import site.coduo.retrospect.repository.RetrospectEntity; import site.coduo.retrospect.repository.RetrospectRepository; @@ -44,7 +44,7 @@ public void createRetrospect( final Member member = memberService.findMemberByCredential(credentialToken); final PairRoomMemberEntity pairRoomMember = pairRoomMemberRepository.fetchByPairRoomAndMember(pairRoom, member); if (retrospectRepository.existsRetrospectEntityByPairRoomMember(pairRoomMember)) { - throw new MaxRetrospectLimitException("회고가 이미 존재합니다."); + throw new DuplicateRetrospectException("해당 페어룸에 대한 사용자의 회고가 이미 존재합니다."); } final RetrospectContents retrospectContents = RetrospectContents.from(answers); final Retrospect retrospect = new Retrospect(retrospectContents); diff --git a/backend/src/test/java/site/coduo/retrospect/service/RetrospectServiceTest.java b/backend/src/test/java/site/coduo/retrospect/service/RetrospectServiceTest.java index dc05960e..3e26ae1e 100644 --- a/backend/src/test/java/site/coduo/retrospect/service/RetrospectServiceTest.java +++ b/backend/src/test/java/site/coduo/retrospect/service/RetrospectServiceTest.java @@ -31,7 +31,7 @@ import site.coduo.pairroom.repository.PairRoomRepository; import site.coduo.referencelink.repository.CategoryRepository; import site.coduo.retrospect.controller.response.FindRetrospectsResponse; -import site.coduo.retrospect.exception.MaxRetrospectLimitException; +import site.coduo.retrospect.exception.DuplicateRetrospectException; import site.coduo.retrospect.repository.RetrospectEntity; import site.coduo.retrospect.repository.RetrospectRepository; import site.coduo.timer.repository.TimerRepository; @@ -134,7 +134,7 @@ void createTwiceRetrospect() { // When && Then assertThatThrownBy( () -> retrospectService.createRetrospect(credentialToken, savedPairRoom.getAccessCode(), answers)) - .isInstanceOf(MaxRetrospectLimitException.class); + .isInstanceOf(DuplicateRetrospectException.class); }