diff --git a/jaknaeso-core/src/main/java/org/nexters/jaknaesocore/domain/survey/dto/SurveyHistoryResponse.java b/jaknaeso-core/src/main/java/org/nexters/jaknaesocore/domain/survey/dto/SurveyHistoryResponse.java index 89cb19cb..94ffb78d 100644 --- a/jaknaeso-core/src/main/java/org/nexters/jaknaesocore/domain/survey/dto/SurveyHistoryResponse.java +++ b/jaknaeso-core/src/main/java/org/nexters/jaknaesocore/domain/survey/dto/SurveyHistoryResponse.java @@ -6,4 +6,21 @@ public record SurveyHistoryResponse( Long bundleId, List surveyHistoryDetails, Integer nextSurveyIndex, - boolean isCompleted) {} + boolean isCompleted) { + + public static SurveyHistoryResponse of( + Long bundleId, + List surveyHistoryDetails, + Integer nextSurveyIndex, + boolean isCompleted) { + return new SurveyHistoryResponse(bundleId, surveyHistoryDetails, nextSurveyIndex, isCompleted); + } + + public static SurveyHistoryResponse createNextBundleSurveyHistory(Long bundleId) { + return new SurveyHistoryResponse(bundleId, List.of(), 1, false); + } + + public static SurveyHistoryResponse createInitialSurveyHistory() { + return new SurveyHistoryResponse(1L, List.of(), 1, false); + } +} diff --git a/jaknaeso-core/src/main/java/org/nexters/jaknaesocore/domain/survey/service/SurveyService.java b/jaknaeso-core/src/main/java/org/nexters/jaknaesocore/domain/survey/service/SurveyService.java index d11dcee5..389cf7bd 100644 --- a/jaknaeso-core/src/main/java/org/nexters/jaknaesocore/domain/survey/service/SurveyService.java +++ b/jaknaeso-core/src/main/java/org/nexters/jaknaesocore/domain/survey/service/SurveyService.java @@ -51,7 +51,7 @@ private List getSubmittedSurvey(final Long memberId) { public SurveyHistoryResponse getSurveyHistory(final Long memberId) { return findLatestSubmission(memberId) .map(this::classifySubmission) - .orElseGet(this::createInitialSurveyHistory); + .orElseGet(SurveyHistoryResponse::createInitialSurveyHistory); } private Optional findLatestSubmission(final Long memberId) { @@ -64,15 +64,15 @@ private SurveyHistoryResponse classifySubmission(SurveySubmission latestSubmissi List submissions = findSubmissionsForBundle(latestSubmission.getMember().getId(), bundle.getId()); - boolean isSubmittedToday = latestSubmission.isSubmittedByDate(LocalDate.now()); - if (isSubmittedToday) { - return createCurrentBundleSurveyHistory(bundle.getId(), submissions, isSubmittedToday); + boolean isCompleted = latestSubmission.isSubmittedByDate(LocalDate.now()); + if (isCompleted) { + return createCurrentBundleSurveyHistory(bundle.getId(), submissions, isCompleted); } if (bundle.isAllSubmitted(submissions)) { return getNextBundleHistory(bundle.getId()); } - return createCurrentBundleSurveyHistory(bundle.getId(), submissions, isSubmittedToday); + return createCurrentBundleSurveyHistory(bundle.getId(), submissions, isCompleted); } private List findSubmissionsForBundle( @@ -80,30 +80,20 @@ private List findSubmissionsForBundle( return surveySubmissionRepository.findByMember_IdAndSurvey_SurveyBundle_Id(memberId, bundleId); } - private SurveyHistoryResponse createInitialSurveyHistory() { - return new SurveyHistoryResponse(1L, List.of(), 1, false); - } - - private SurveyHistoryResponse createNextBundleSurveyHistory(final Long bundleId) { - return new SurveyHistoryResponse(bundleId, List.of(), 1, false); - } - private SurveyHistoryResponse createCurrentBundleSurveyHistory( Long bundleId, List submissions, boolean isSubmittedToday) { List historyDetails = submissions.stream().map(BaseEntity::getId).map(SurveyHistoryDetailResponse::of).toList(); if (isSubmittedToday) { - return new SurveyHistoryResponse( - bundleId, historyDetails, historyDetails.size(), isSubmittedToday); + return SurveyHistoryResponse.of(bundleId, historyDetails, historyDetails.size(), true); } - return new SurveyHistoryResponse( - bundleId, historyDetails, historyDetails.size() + 1, isSubmittedToday); + return SurveyHistoryResponse.of(bundleId, historyDetails, historyDetails.size() + 1, false); } private SurveyHistoryResponse getNextBundleHistory(Long currentBundleId) { return surveyBundleRepository .findFirstByIdGreaterThanOrderByIdAsc(currentBundleId) - .map(bundle -> createNextBundleSurveyHistory(bundle.getId())) + .map(bundle -> SurveyHistoryResponse.createNextBundleSurveyHistory(bundle.getId())) .orElseThrow(() -> CustomException.NOT_READY_FOR_NEXT_BUNDLE); }