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..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,10 +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)); + + return findById(id).orElseThrow( + () -> { + 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); + }); } } 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);