diff --git a/src/main/java/com/bamdoliro/maru/application/form/QueryAllFormUseCase.java b/src/main/java/com/bamdoliro/maru/application/form/QueryAllFormUseCase.java index 179dd360..3236b2a8 100644 --- a/src/main/java/com/bamdoliro/maru/application/form/QueryAllFormUseCase.java +++ b/src/main/java/com/bamdoliro/maru/application/form/QueryAllFormUseCase.java @@ -3,7 +3,6 @@ import com.bamdoliro.maru.domain.form.domain.Form; import com.bamdoliro.maru.domain.form.domain.type.FormStatus; import com.bamdoliro.maru.domain.form.domain.type.FormType; -import com.bamdoliro.maru.domain.form.exception.MissingTotalScoreException; import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; import com.bamdoliro.maru.presentation.form.dto.response.FormSimpleResponse; import com.bamdoliro.maru.shared.annotation.UseCase; @@ -25,13 +24,14 @@ public List execute(FormStatus status, FormType.Category cat .filter(form -> Objects.isNull(category) || form.getType().categoryEquals(category)) .toList()); - if (sort != null && formList.stream().anyMatch(form -> form.getScore().getTotalScore() == null)) { - throw new MissingTotalScoreException(); - } - if ("total-score-asc".equals(sort)) { - formList.sort(Comparator.comparing(form -> form.getScore().getTotalScore(), Comparator.naturalOrder())); - } else if ("total-score-desc".equals(sort)) { - formList.sort(Comparator.comparing(form -> form.getScore().getTotalScore(), Comparator.reverseOrder())); + if (sort != null) { + switch (sort) { + case "total-score-asc" -> + formList.sort(Comparator.comparing(form -> form.getScore().getTotalScore(), Comparator.nullsLast(Comparator.naturalOrder()))); + case "total-score-desc" -> + formList.sort(Comparator.comparing(form -> form.getScore().getTotalScore(), Comparator.nullsLast(Comparator.reverseOrder()))); + case "form-id" -> formList.sort(Comparator.comparing(Form::getId)); + } } return formList.stream() diff --git a/src/test/java/com/bamdoliro/maru/application/form/QueryAllFormUseCaseTest.java b/src/test/java/com/bamdoliro/maru/application/form/QueryAllFormUseCaseTest.java index 62671975..5f2e03d9 100644 --- a/src/test/java/com/bamdoliro/maru/application/form/QueryAllFormUseCaseTest.java +++ b/src/test/java/com/bamdoliro/maru/application/form/QueryAllFormUseCaseTest.java @@ -170,4 +170,25 @@ class QueryAllFormUseCaseTest { verify(formRepository, times(1)).findByStatus(null); } + + @Test + void 접수번호가_높은_순으로_조회한다() { + // given + List
formList = List.of( + FormFixture.createForm(FormType.REGULAR), + FormFixture.createForm(FormType.SPECIAL_ADMISSION), + FormFixture.createForm(FormType.MEISTER_TALENT), + FormFixture.createForm(FormType.MULTI_CHILDREN) + ); + + given(formRepository.findByStatus(null)).willReturn(formList); + + // when + List returnedFormList = queryAllFormUseCase.execute(null, FormType.Category.SOCIAL_INTEGRATION, "form-id"); + + // then + assertEquals(1, returnedFormList.size()); + + verify(formRepository, times(1)).findByStatus(null); + } } \ No newline at end of file diff --git a/src/test/java/com/bamdoliro/maru/presentation/form/FormControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/form/FormControllerTest.java index f7179446..98b01e3e 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/form/FormControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/form/FormControllerTest.java @@ -1272,7 +1272,7 @@ class FormControllerTest extends RestDocsTestSupport { .description("<>") .optional(), parameterWithName("sort") - .description("정렬 기준 (최종 점수 오름차순인 경우 total-score-asc, 최종 점수 내림차순인 경우 total-score-desc, null인 경우 수험번호 오름차순 조회)") + .description("정렬 기준 (total-score-asc인 경우 최종 점수 오름차순, total-score-desc인 경우 최종 점수 내림차순, form-id인 경우 접수 번호순, null인 경우 수험번호 오름차순 조회)") .optional() ) ));