Skip to content

Commit

Permalink
Merge pull request #161 from Bamdoliro/perf/#160
Browse files Browse the repository at this point in the history
[개선] 어드민 분석 기능 개선
  • Loading branch information
jyj1289 authored Oct 19, 2024
2 parents c8b8da8 + 311f917 commit 30b090a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ else if (mainCategory.equals(FormType.Category.SUPERNUMERARY))
Map<FormType.Category, List<Form>> formLists = subCategories.stream()
.collect(Collectors.toMap(
category -> category,
category -> formRepository.findByCategory(category).stream()
.filter(form -> request.getStatusList().contains(form.getStatus()))
.collect(Collectors.toList())
category -> {
if (request.getType().equals("ORIGINAL")) {
return formRepository.findByOriginalCategory(category).stream()
.filter(form -> request.getStatusList().contains(form.getStatus()))
.toList();
}
return formRepository.findByCategory(category).stream()
.filter(form -> request.getStatusList().contains(form.getStatus()))
.toList();
}
));

for(Map.Entry<FormType.Category, List<Form>> entry : formLists.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.bamdoliro.maru.shared.annotation.UseCase;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -15,11 +16,19 @@ public class QueryNumberOfApplicantsUseCase {

private final FormRepository formRepository;

public List<NumberOfApplicantsResponse> execute() {
List<NumberOfApplicantsResponse> result = formRepository.findTypeAndCountGroupByType()
.stream()
.map(NumberOfApplicantsResponse::new)
.collect(Collectors.toList());
public List<NumberOfApplicantsResponse> execute(String type) {
List<NumberOfApplicantsResponse> result = new ArrayList<>();
if (type.equals("ORIGINAL")) {
result = formRepository.findOriginalTypeAndCountGroupByType()
.stream()
.map(NumberOfApplicantsResponse::new)
.collect(Collectors.toList());
} else {
result = formRepository.findTypeAndCountGroupByType()
.stream()
.map(NumberOfApplicantsResponse::new)
.collect(Collectors.toList());
}

List<FormType> existingTypes = result
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface FormRepositoryCustom {
List<Form> findByStatus(FormStatus status);
List<Form> findByType(FormType type);
List<Form> findByCategory(FormType.Category category);
List<Form> findByOriginalCategory(FormType.Category category);
List<Form> findReceivedSpecialForm();
List<Form> findReceivedRegularForm();
List<Form> findReceivedSupernumeraryForm();
Expand All @@ -29,6 +30,7 @@ public interface FormRepositoryCustom {
List<Form> findByFormIdList(List<Long> idList);
List<FormUrlVo> findFormUrlByFormIdList(List<Long> idList);
List<NumberOfApplicantsVo> findTypeAndCountGroupByType();
List<NumberOfApplicantsVo> findOriginalTypeAndCountGroupByType();
List<GradeVo> findGradeGroupByTypeAndStatus(List<FormStatus> round);
List<SchoolStatusVo> findSchoolByAddress(List<FormStatus> round, String keyword);
List<SchoolStatusVo> findNotBusanSchool(List<FormStatus> round);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ public List<Form> findByCategory(FormType.Category category) {
.fetch();
}

@Override
public List<Form> findByOriginalCategory(FormType.Category category) {
List<FormType> matchingFormTypes = getFormTypesByCategory(category);

return queryFactory
.selectFrom(form)
.where(form.originalType.in(matchingFormTypes))
.orderBy(form.examinationNumber.asc())
.fetch();
}

private BooleanExpression eqStatus(FormStatus status) {
if (Objects.isNull(status)) {
return null;
Expand Down Expand Up @@ -274,6 +285,18 @@ public List<NumberOfApplicantsVo> findTypeAndCountGroupByType() {
.fetch();
}

@Override
public List<NumberOfApplicantsVo> findOriginalTypeAndCountGroupByType() {
return queryFactory
.select(new QNumberOfApplicantsVo(
form.originalType,
form.count()
))
.from(form)
.groupBy(form.originalType)
.fetch();
}

@Override
public List<GradeVo> findGradeGroupByTypeAndStatus(List<FormStatus> round) {
return queryFactory
Expand Down Expand Up @@ -317,6 +340,7 @@ public List<SchoolStatusVo> findNotBusanSchool(List<FormStatus> round) {
))
.from(form)
.where(form.education.school.location.eq("부산광역시").not())
.orderBy(form.applicant.name.asc())
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ public class AnalysisController {

@GetMapping("/number-of-applicants")
public ListCommonResponse<NumberOfApplicantsResponse> getNumberOfApplicants(
@AuthenticationPrincipal(authority = Authority.ADMIN)User user
@AuthenticationPrincipal(authority = Authority.ADMIN)User user,
@RequestParam String type
) {
return CommonResponse.ok(
queryNumberOfApplicantsUseCase.execute()
queryNumberOfApplicantsUseCase.execute(type)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public class GenderRatioRequest {

@NotNull(message = "필수값입니다.")
private FormType.Category mainCategory;

@NotNull(message = "필수값입니다.")
private String type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class QueryGenderRatioUseCaseTest {

given(formRepository.findByCategory(FormType.Category.REGULAR)).willReturn(formList);
List<FormStatus> round = List.of(FormStatus.FIRST_PASSED, FormStatus.FAILED, FormStatus.PASSED);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.REGULAR);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.REGULAR, "CURRENT");

// when
List<GenderRatioResponse> responseList = queryGenderRatioUseCase.execute(request);
Expand Down Expand Up @@ -79,7 +79,7 @@ class QueryGenderRatioUseCaseTest {
.filter(form -> form.getType().categoryEquals(FormType.Category.SOCIAL_INTEGRATION))
.toList());
List<FormStatus> round = List.of(FormStatus.FIRST_PASSED, FormStatus.FAILED, FormStatus.PASSED);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SPECIAL);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SPECIAL, "CURRENT");

// when
List<GenderRatioResponse> responseList = queryGenderRatioUseCase.execute(request);
Expand Down Expand Up @@ -115,7 +115,7 @@ class QueryGenderRatioUseCaseTest {
.filter(form -> form.getType().categoryEquals(FormType.Category.SPECIAL_ADMISSION))
.toList());
List<FormStatus> round = List.of(FormStatus.FIRST_PASSED, FormStatus.FAILED, FormStatus.PASSED);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SUPERNUMERARY);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SUPERNUMERARY, "CURRENT");

// when
List<GenderRatioResponse> responseList = queryGenderRatioUseCase.execute(request);
Expand Down Expand Up @@ -143,7 +143,7 @@ class QueryGenderRatioUseCaseTest {

given(formRepository.findByCategory(FormType.Category.REGULAR)).willReturn(formList);
List<FormStatus> round = List.of(FormStatus.FAILED, FormStatus.PASSED);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.REGULAR);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.REGULAR, "CURRENT");

// when
List<GenderRatioResponse> responseList = queryGenderRatioUseCase.execute(request);
Expand Down Expand Up @@ -181,7 +181,7 @@ class QueryGenderRatioUseCaseTest {
.filter(form -> form.getType().categoryEquals(FormType.Category.SOCIAL_INTEGRATION))
.toList());
List<FormStatus> round = List.of(FormStatus.FAILED, FormStatus.PASSED);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SPECIAL);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SPECIAL, "CURRENT");

// when
List<GenderRatioResponse> responseList = queryGenderRatioUseCase.execute(request);
Expand Down Expand Up @@ -217,7 +217,7 @@ class QueryGenderRatioUseCaseTest {
.filter(form -> form.getType().categoryEquals(FormType.Category.SPECIAL_ADMISSION))
.toList());
List<FormStatus> round = List.of(FormStatus.FAILED, FormStatus.PASSED);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SUPERNUMERARY);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SUPERNUMERARY, "CURRENT");

// when
List<GenderRatioResponse> responseList = queryGenderRatioUseCase.execute(request);
Expand Down Expand Up @@ -245,7 +245,7 @@ class QueryGenderRatioUseCaseTest {

given(formRepository.findByCategory(FormType.Category.REGULAR)).willReturn(formList);
List<FormStatus> round = List.of(FormStatus.PASSED);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.REGULAR);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.REGULAR, "CURRENT");

// when
List<GenderRatioResponse> responseList = queryGenderRatioUseCase.execute(request);
Expand Down Expand Up @@ -283,7 +283,7 @@ class QueryGenderRatioUseCaseTest {
.filter(form -> form.getType().categoryEquals(FormType.Category.SOCIAL_INTEGRATION))
.toList());
List<FormStatus> round = List.of(FormStatus.PASSED);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SPECIAL);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SPECIAL, "CURRENT");

// when
List<GenderRatioResponse> responseList = queryGenderRatioUseCase.execute(request);
Expand Down Expand Up @@ -319,7 +319,7 @@ class QueryGenderRatioUseCaseTest {
.filter(form -> form.getType().categoryEquals(FormType.Category.SPECIAL_ADMISSION))
.toList());
List<FormStatus> round = List.of(FormStatus.FIRST_PASSED, FormStatus.FAILED, FormStatus.PASSED);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SUPERNUMERARY);
GenderRatioRequest request = new GenderRatioRequest(round, FormType.Category.SUPERNUMERARY, "CURRENT");

// when
List<GenderRatioResponse> responseList = queryGenderRatioUseCase.execute(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class QueryNumberOfApplicantsUseCaseTest {
given(formRepository.findTypeAndCountGroupByType()).willReturn(voList);

// when
List<NumberOfApplicantsResponse> responseList = queryNumberOfApplicantsUseCase.execute();
List<NumberOfApplicantsResponse> responseList = queryNumberOfApplicantsUseCase.execute("CURRENT");

// then
assertEquals(responseList.size(), FormType.values().length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ class AnalysisControllerTest extends RestDocsTestSupport {
User user = UserFixture.createAdminUser();
given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true);
given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user);
given(queryNumberOfApplicantsUseCase.execute()).willReturn(AnalysisFixture.createNumberOfApplicantsResponseList());
given(queryNumberOfApplicantsUseCase.execute(any(String.class))).willReturn(AnalysisFixture.createNumberOfApplicantsResponseList());

mockMvc.perform(get("/analysis/number-of-applicants")
.param("type", "CURRENT")
.header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader())
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(restDocs.document(
requestHeaders(
headerWithName(HttpHeaders.AUTHORIZATION).description("Bearer token")
),
queryParameters(
parameterWithName("type")
.description("CURRENT(지원전형) / ORIGINAL(최종 전형)")
)
));
}
Expand All @@ -71,7 +76,7 @@ class AnalysisControllerTest extends RestDocsTestSupport {
),
queryParameters(
parameterWithName("statusList")
.description("조회할 원서 상태 목록(1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)")
.description("조회할 원서 상태 목록(전체 조회면, RECEIVED, FIRST_PASSED, FAILED, PASSED, 1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)")
)
));
}
Expand All @@ -97,7 +102,7 @@ class AnalysisControllerTest extends RestDocsTestSupport {
),
queryParameters(
parameterWithName("statusList")
.description("조회할 원서 상태 목록(1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)")
.description("조회할 원서 상태 목록(전체 조회면, RECEIVED, FIRST_PASSED, FAILED, PASSED, 1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)")
)
));
}
Expand All @@ -123,7 +128,7 @@ class AnalysisControllerTest extends RestDocsTestSupport {
),
queryParameters(
parameterWithName("statusList")
.description("조회할 원서 상태 목록(1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)")
.description("조회할 원서 상태 목록(전체 조회면, RECEIVED, FIRST_PASSED, FAILED, PASSED, 1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)")
)
));
}
Expand All @@ -136,6 +141,7 @@ class AnalysisControllerTest extends RestDocsTestSupport {
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
multiValueMap.put("statusList", List.of("FIRST_PASSED", "FAILED", "PASSED"));
multiValueMap.add("mainCategory", "REGULAR");
multiValueMap.add("type", "CURRENT");
given(queryGenderRatioUseCase.execute(any(GenderRatioRequest.class))).willReturn(AnalysisFixture.createGenderRatioResponse(
FormType.Category.valueOf(Objects.requireNonNull(multiValueMap.get("mainCategory")).get(0))
));
Expand All @@ -154,9 +160,11 @@ class AnalysisControllerTest extends RestDocsTestSupport {
),
queryParameters(
parameterWithName("statusList")
.description("조회할 원서 상태 목록(1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)"),
.description("조회할 원서 상태 목록(전체 조회면, RECEIVED, FIRST_PASSED, FAILED, PASSED, 1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)"),
parameterWithName("mainCategory")
.description("메인 카테고리(FormType.Category 참고)")
.description("메인 카테고리(FormType.Category 참고)"),
parameterWithName("type")
.description("CURRENT(지원전형) / ORIGINAL(최종 전형)")
)
));
}
Expand Down Expand Up @@ -186,7 +194,7 @@ class AnalysisControllerTest extends RestDocsTestSupport {
),
queryParameters(
parameterWithName("statusList")
.description("조회할 원서 상태 목록(1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)"),
.description("조회할 원서 상태 목록(전체 조회면, RECEIVED, FIRST_PASSED, FAILED, PASSED, 1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)"),
parameterWithName("isBusan")
.description("부산 지역 학교 검색 여부(true면 부산, false면 부산 외 다른 모든 타지역)"),
parameterWithName("gu")
Expand Down Expand Up @@ -220,7 +228,7 @@ class AnalysisControllerTest extends RestDocsTestSupport {
),
queryParameters(
parameterWithName("statusList")
.description("조회할 원서 상태 목록(1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)"),
.description("조회할 원서 상태 목록(전체 조회면, RECEIVED, FIRST_PASSED, FAILED, PASSED, 1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)"),
parameterWithName("isBusan")
.description("부산 지역 학교 검색 여부(true면 부산, false면 부산 외 다른 모든 타지역)"),
parameterWithName("gu")
Expand Down Expand Up @@ -254,7 +262,7 @@ class AnalysisControllerTest extends RestDocsTestSupport {
),
queryParameters(
parameterWithName("statusList")
.description("조회할 원서 상태 목록(1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)"),
.description("조회할 원서 상태 목록(전체 조회면, RECEIVED, FIRST_PASSED, FAILED, PASSED, 1차 합격자면 FIRST_PASSED, FAILED, PASSED, 2차 전형자면 FAILED, PASSED, 최종 합격자면 PASSED)"),
parameterWithName("isBusan")
.description("부산 지역 학교 검색 여부(true면 부산, false면 부산 외 다른 모든 타지역)"),
parameterWithName("gu")
Expand Down

0 comments on commit 30b090a

Please sign in to comment.