Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<DailyProgressResponse> dailyProgresses,
List<ProblemSetHomeFeedResponse> problemSets
) {
private static final Logger log = LoggerFactory.getLogger(HomeFeedResponse.class);

public static HomeFeedResponse of(
List<DailyProgressResponse> dailyProgresses,
List<ProblemSetHomeFeedResponse> problemSets
Expand All @@ -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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Problem, Long> {

Logger log = LoggerFactory.getLogger(ProblemRepository.class);

boolean existsByProblemCustomId(ProblemCustomId problemCustomId);

default void existsByIdElseThrow(Long id) {
Expand All @@ -25,10 +29,18 @@ default void existsByIdElseThrow(Long id) {
Optional<Problem> 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);
});
}
}
Original file line number Diff line number Diff line change
@@ -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);
Expand Down