Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[개선] 원서 전체 조회 정렬 옵션 추가 #128

Merged
merged 3 commits into from
Sep 7, 2024
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,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
Loading