Skip to content

Commit

Permalink
[SL-17 CHORE] null값 지원서 반환 및 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyoungpark00 committed Dec 30, 2023
1 parent 9a8bf42 commit f7cc700
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public class ApplicationListWithSubmittedResponse {

// member의 작성 application의 List
private List<ApplicationListGetResponse> applicationList;

// null값으로 채워진 ApplicationList
private ApplicationListGetResponse defaultApplicationList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,35 @@ public ApplicationListWithSubmittedResponse getApplicationList(Long userId) {
List<Application> applications = applicationJpaRepository.findByUserUserId(userId);

// applications 리스트를 순회하면서 status가 "Y"인 application이 있는지 확인
boolean isSubmittedExists = applications.stream()
.anyMatch(application -> "Y".equals(application.getStatus()));
boolean isSubmittedExists = checkIsSubmitted(applications);

// boolean을 String으로 변환
String isSubmitted = isSubmittedExists ? "Y" : "N";
String isSubmitted = boolToString(isSubmittedExists);

// 지원서 리스트 가져오기
List<ApplicationListGetResponse> applicationList = loadApplicationList(applications);

// null값 지원서
ApplicationListGetResponse defaultApplication = ApplicationListGetResponse.of(null,null,null,null,null);


return new ApplicationListWithSubmittedResponse(isSubmitted, applicationList, defaultApplication);
}

// 제출된 지원서 있는지 체크
private boolean checkIsSubmitted(List<Application> applications){
boolean isSubmitted = applications.stream()
.anyMatch(application -> "Y".equals(application.getStatus()));
return isSubmitted;
}

// boolean을 String으로 변환
private String boolToString(boolean bool){
return bool ? "Y" : "N";
}

// 지원서 리스트 불러오기
private List<ApplicationListGetResponse> loadApplicationList(List<Application> applications){
List<ApplicationListGetResponse> applicationList = applications.stream()
.map(application -> ApplicationListGetResponse.of(
application.getApplicationId(),
Expand All @@ -38,6 +61,6 @@ public ApplicationListWithSubmittedResponse getApplicationList(Long userId) {
application.getStatus()))
.collect(Collectors.toList());

return new ApplicationListWithSubmittedResponse(isSubmitted, applicationList);
return applicationList;
}
}

0 comments on commit f7cc700

Please sign in to comment.