Skip to content

Commit

Permalink
Merge pull request #128 from Bamdoliro/perf/#124
Browse files Browse the repository at this point in the history
[개선] 원서 전체 조회 정렬 옵션 추가
  • Loading branch information
cabbage16 committed Sep 7, 2024
2 parents c62bdb6 + fdc5f95 commit d0d5dce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,13 +24,14 @@ public List<FormSimpleResponse> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,25 @@ class QueryAllFormUseCaseTest {

verify(formRepository, times(1)).findByStatus(null);
}

@Test
void 접수번호가_높은_순으로_조회한다() {
// given
List<Form> 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<FormSimpleResponse> returnedFormList = queryAllFormUseCase.execute(null, FormType.Category.SOCIAL_INTEGRATION, "form-id");

// then
assertEquals(1, returnedFormList.size());

verify(formRepository, times(1)).findByStatus(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ class FormControllerTest extends RestDocsTestSupport {
.description("<<form-type,원서 유형 (null인 경우 전체 조회)>>")
.optional(),
parameterWithName("sort")
.description("정렬 기준 (최종 점수 오름차순인 경우 total-score-asc, 최종 점수 내림차순인 경우 total-score-desc, null인 경우 수험번호 오름차순 조회)")
.description("정렬 기준 (total-score-asc인 경우 최종 점수 오름차순, total-score-desc인 경우 최종 점수 내림차순, form-id인 경우 접수 번호순, null인 경우 수험번호 오름차순 조회)")
.optional()
)
));
Expand Down

0 comments on commit d0d5dce

Please sign in to comment.