From 7bed49ab716be18fa57bebb7e50525f2fbbe1604 Mon Sep 17 00:00:00 2001 From: luna156 Date: Mon, 19 Aug 2024 12:02:10 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=EC=95=88=EC=93=B0=EB=8A=94=20r?= =?UTF-8?q?epository=20method=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../podoarrival/event/repository/EventRewardRepository.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/softeer/podoarrival/event/repository/EventRewardRepository.java b/src/main/java/com/softeer/podoarrival/event/repository/EventRewardRepository.java index 4b9673e..b8d9434 100644 --- a/src/main/java/com/softeer/podoarrival/event/repository/EventRewardRepository.java +++ b/src/main/java/com/softeer/podoarrival/event/repository/EventRewardRepository.java @@ -7,6 +7,5 @@ import java.util.List; public interface EventRewardRepository extends JpaRepository { - int countByEvent(Event event); - List findAllByEvent(Event event); + List findAllByEvent(Event event); } From 22a63b48814bba7c47ed7c0c20aafa64c4877891 Mon Sep 17 00:00:00 2001 From: luna156 Date: Mon, 19 Aug 2024 12:03:52 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20quiz=EB=A5=BC=20DB=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AA=BB=EC=B0=BE=EC=9D=84=20=EC=8B=9C=20exception?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DB에서 찾은 quiz가 null일때 체크 후 exception 추가 - exception handler에 해당 exception 추가 및 ErrorCode 추가 --- .../com/softeer/podoarrival/common/response/ErrorCode.java | 3 ++- .../event/exception/ArrivalEventExceptionHandler.java | 6 ++++++ .../com/softeer/podoarrival/event/service/QuizService.java | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/softeer/podoarrival/common/response/ErrorCode.java b/src/main/java/com/softeer/podoarrival/common/response/ErrorCode.java index b3a8a2b..a9946b4 100644 --- a/src/main/java/com/softeer/podoarrival/common/response/ErrorCode.java +++ b/src/main/java/com/softeer/podoarrival/common/response/ErrorCode.java @@ -23,7 +23,8 @@ public enum ErrorCode { USERNAME_EXISTS_ERROR(false, HttpStatus.BAD_REQUEST.value(), "이미 존재하는 닉네임입니다."), //event_arrival - PHONENUM_EXISTS_ERROR(false, HttpStatus.BAD_REQUEST.value(),"이미 응모한 전화번호입니다.") + PHONENUM_EXISTS_ERROR(false, HttpStatus.BAD_REQUEST.value(),"이미 응모한 전화번호입니다."), + QUIZ_NOT_FOUND(false, HttpStatus.NOT_FOUND.value(), "오늘 날짜에 퀴즈가 없습니다.") ; diff --git a/src/main/java/com/softeer/podoarrival/event/exception/ArrivalEventExceptionHandler.java b/src/main/java/com/softeer/podoarrival/event/exception/ArrivalEventExceptionHandler.java index 8839b02..5d7cbb8 100644 --- a/src/main/java/com/softeer/podoarrival/event/exception/ArrivalEventExceptionHandler.java +++ b/src/main/java/com/softeer/podoarrival/event/exception/ArrivalEventExceptionHandler.java @@ -28,4 +28,10 @@ public CommonResponse asyncRequestExecuteException(AsyncRequestExecuteExcepti return new CommonResponse<>(ErrorCode.INTERNAL_SERVER_ERROR); } + @ExceptionHandler(DailyQuizNotExistsException.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + public CommonResponse dailyQuizNotFoundException(DailyQuizNotExistsException e, HttpServletRequest request) { + log.warn("ARRIVAL-003> 요청 URI: " + request.getRequestURI() + ", 에러 메세지: " + e.getMessage()); + return new CommonResponse<>(ErrorCode.QUIZ_NOT_FOUND); + } } diff --git a/src/main/java/com/softeer/podoarrival/event/service/QuizService.java b/src/main/java/com/softeer/podoarrival/event/service/QuizService.java index 02a7b78..e55cd1e 100644 --- a/src/main/java/com/softeer/podoarrival/event/service/QuizService.java +++ b/src/main/java/com/softeer/podoarrival/event/service/QuizService.java @@ -1,5 +1,6 @@ package com.softeer.podoarrival.event.service; +import com.softeer.podoarrival.event.exception.DailyQuizNotExistsException; import com.softeer.podoarrival.event.model.dto.GetQuizResponseDto; import com.softeer.podoarrival.event.model.entity.Quiz; import com.softeer.podoarrival.event.repository.QuizRepository; @@ -43,9 +44,9 @@ public GetQuizResponseDto getQuizInfo() { // cache miss if(quizDto.isInvalid()) { Quiz quiz = quizRepository.findByEventDate(LocalDate.now()); + if(quiz == null) {throw new DailyQuizNotExistsException("오늘 날짜에는 퀴즈가 존재하지 않습니다.");} setQuizToRedis(quiz); return QuizMapper.mapQuizToGetQuizResponseDto(quiz); - } // cache hit else { From f2d02a7c46f0095b5a0fc82da21fabe42670f72d Mon Sep 17 00:00:00 2001 From: luna156 Date: Mon, 19 Aug 2024 12:17:24 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=EC=84=A0=EC=B0=A9=EC=88=9C=20?= =?UTF-8?q?=EC=9D=91=EB=AA=A8=20=EA=B3=BC=EC=A0=95=EC=97=90=EC=84=9C=20exc?= =?UTF-8?q?eption=20Slf4j=20=EB=A1=9C=EA=B7=B8=20=EB=82=A8=EA=B8=B0?= =?UTF-8?q?=EA=B8=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../podoarrival/event/controller/ArrivalEventController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/softeer/podoarrival/event/controller/ArrivalEventController.java b/src/main/java/com/softeer/podoarrival/event/controller/ArrivalEventController.java index 9d6c6bc..61328fd 100644 --- a/src/main/java/com/softeer/podoarrival/event/controller/ArrivalEventController.java +++ b/src/main/java/com/softeer/podoarrival/event/controller/ArrivalEventController.java @@ -36,6 +36,7 @@ public CompletableFuture> arrivalE if(ex.getCause() instanceof ExistingUserException) { throw new ExistingUserException("[비동기 에러] 유저가 이미 존재합니다."); } else { + log.error("Exception occurred while arrival application", ex); throw new AsyncRequestExecuteException("[비동기 에러] 선착순 요청 중 서버 오류 발생"); } }); From ee25e29f7f5af344bfb4b77355a14bccd7839aae Mon Sep 17 00:00:00 2001 From: luna156 Date: Mon, 19 Aug 2024 14:23:06 +0900 Subject: [PATCH 4/4] =?UTF-8?q?test:=20=EB=B0=94=EA=BE=BC=20exception?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/softeer/podoarrival/unit/quiz/GetQuizListTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/softeer/podoarrival/unit/quiz/GetQuizListTest.java b/src/test/java/com/softeer/podoarrival/unit/quiz/GetQuizListTest.java index 0d772a1..00921ef 100644 --- a/src/test/java/com/softeer/podoarrival/unit/quiz/GetQuizListTest.java +++ b/src/test/java/com/softeer/podoarrival/unit/quiz/GetQuizListTest.java @@ -1,5 +1,6 @@ package com.softeer.podoarrival.unit.quiz; +import com.softeer.podoarrival.event.exception.DailyQuizNotExistsException; import com.softeer.podoarrival.unit.base.QuizServiceBase; import com.softeer.podoarrival.event.model.dto.GetQuizResponseDto; import com.softeer.podoarrival.event.model.entity.Quiz; @@ -85,7 +86,7 @@ public void getQuizListFail_CacheMiss() { // when-then assertThatThrownBy(() -> quizService.getQuizInfo()) - .isInstanceOf(NullPointerException.class); + .isInstanceOf(DailyQuizNotExistsException.class); } }