From 375823ebee8bec4a5ad19f83b7cc9990fd04072c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B8=EC=A4=80?= <74056843+sejoon00@users.noreply.github.com> Date: Sun, 30 Mar 2025 17:03:26 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[hotfix]=20=EB=AC=B8=ED=95=AD=20=EB=AA=BB?= =?UTF-8?q?=EC=B0=BE=EC=9D=84=20=EB=95=8C=20=EB=B2=88=ED=98=B8=20=EB=A1=9C?= =?UTF-8?q?=EA=B9=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homefeed/dto/response/HomeFeedResponse.java | 16 +++++++++++++++- .../problem/repository/ProblemRepository.java | 3 ++- .../error/exception/NotFoundException.java | 6 +++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/moplus/moplus_server/client/homefeed/dto/response/HomeFeedResponse.java b/src/main/java/com/moplus/moplus_server/client/homefeed/dto/response/HomeFeedResponse.java index 7699cb6a..f2d0842d 100644 --- a/src/main/java/com/moplus/moplus_server/client/homefeed/dto/response/HomeFeedResponse.java +++ b/src/main/java/com/moplus/moplus_server/client/homefeed/dto/response/HomeFeedResponse.java @@ -3,13 +3,19 @@ import com.moplus.moplus_server.admin.problemset.dto.response.ProblemSetGetResponse; import com.moplus.moplus_server.admin.problemset.dto.response.ProblemSummaryResponse; import com.moplus.moplus_server.client.submit.domain.ProgressStatus; +import com.moplus.moplus_server.global.error.exception.ErrorCode; +import com.moplus.moplus_server.global.error.exception.NotFoundException; import java.time.LocalDate; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public record HomeFeedResponse( List dailyProgresses, List problemSets ) { + private static final Logger log = LoggerFactory.getLogger(HomeFeedResponse.class); + public static HomeFeedResponse of( List dailyProgresses, List problemSets @@ -36,12 +42,20 @@ public record ProblemSetHomeFeedResponse( public static ProblemSetHomeFeedResponse of(LocalDate date, Long publishId, ProblemSetGetResponse problemSetGetResponse, Long submitCount) { + ProblemSummaryResponse problemSummaryResponse = null; + try { + problemSummaryResponse = problemSetGetResponse.problemSummaries().get(0); + } catch (IndexOutOfBoundsException e) { + log.atError().log("id " + publishId + "번 발행에 속한 세트에 문항이 존재하지 않습니다. "); + throw new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND, + "id " + publishId + "번 발행에 속한 세트에 문항이 존재하지 않습니다. "); + } return new ProblemSetHomeFeedResponse( date, publishId, problemSetGetResponse.title(), submitCount, - ProblemHomeFeedResponse.of(problemSetGetResponse.problemSummaries().get(0)) + ProblemHomeFeedResponse.of(problemSummaryResponse) ); } diff --git a/src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java b/src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java index 0a959fc9..b40ea0f0 100644 --- a/src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java +++ b/src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java @@ -25,7 +25,8 @@ default void existsByIdElseThrow(Long id) { Optional findByIdWithFetchJoin(@Param("id") Long id); default Problem findByIdElseThrow(Long id) { - return findById(id).orElseThrow(() -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND)); + return findById(id).orElseThrow( + () -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND, id + "번 문제가 존재하지 않습니다.")); } default Problem findByIdWithFetchJoinElseThrow(Long id) { diff --git a/src/main/java/com/moplus/moplus_server/global/error/exception/NotFoundException.java b/src/main/java/com/moplus/moplus_server/global/error/exception/NotFoundException.java index b2c4b5be..0c8247cf 100644 --- a/src/main/java/com/moplus/moplus_server/global/error/exception/NotFoundException.java +++ b/src/main/java/com/moplus/moplus_server/global/error/exception/NotFoundException.java @@ -1,6 +1,10 @@ package com.moplus.moplus_server.global.error.exception; -public class NotFoundException extends BusinessException{ +public class NotFoundException extends BusinessException { + + public NotFoundException(ErrorCode errorCode, String message) { + super(message, errorCode); + } public NotFoundException(ErrorCode errorCode) { super(errorCode); From d6cd898976297623b116a0189067df8c2e9135a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B8=EC=A4=80?= <74056843+sejoon00@users.noreply.github.com> Date: Sun, 30 Mar 2025 17:08:26 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[hotfix]=20=EB=AC=B8=ED=95=AD=20=EB=AA=BB?= =?UTF-8?q?=EC=B0=BE=EC=9D=84=20=EB=95=8C=20=EB=B2=88=ED=98=B8=20=EB=A1=9C?= =?UTF-8?q?=EA=B9=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../problem/repository/ProblemRepository.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java b/src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java index b40ea0f0..d2f4c4e2 100644 --- a/src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java +++ b/src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java @@ -5,12 +5,16 @@ import com.moplus.moplus_server.global.error.exception.ErrorCode; import com.moplus.moplus_server.global.error.exception.NotFoundException; import java.util.Optional; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; public interface ProblemRepository extends JpaRepository { + Logger log = LoggerFactory.getLogger(ProblemRepository.class); + boolean existsByProblemCustomId(ProblemCustomId problemCustomId); default void existsByIdElseThrow(Long id) { @@ -25,11 +29,18 @@ default void existsByIdElseThrow(Long id) { Optional findByIdWithFetchJoin(@Param("id") Long id); default Problem findByIdElseThrow(Long id) { + return findById(id).orElseThrow( - () -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND, id + "번 문제가 존재하지 않습니다.")); + () -> { + log.atError().log("id " + id + "번 문항이 존재하지 않습니다."); + throw new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND); + }); } default Problem findByIdWithFetchJoinElseThrow(Long id) { - return findByIdWithFetchJoin(id).orElseThrow(() -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND)); + return findByIdWithFetchJoin(id).orElseThrow(() -> { + log.atError().log("id " + id + "번 문항이 존재하지 않습니다."); + throw new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND); + }); } }