Skip to content

Commit

Permalink
fix: Modify filtering logic (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanna29 committed Dec 7, 2023
1 parent 3feb687 commit d5b949b
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ private MemberResponseDto createMemberResponseDto(Member member, FilterOptionsRe
boolean bookmark = bookmarkRepository.existsByTargetMemberId(member.getId());
// generationResponseDtoList 만들기 위해 함수 호출
List<GenerationResponseDto> generationResponseDtoList = createGenerationResponseDtoList(member, filterOptionsRequestDto);
// 필터링
generationResponseDtoList=generationResponseDtoList.stream()
.filter(generationList -> (filterOptionsRequestDto.getDepartments().isEmpty() || filterOptionsRequestDto.getDepartments().contains(generationList.getDepartment())) ||
(filterOptionsRequestDto.getLevels().isEmpty() || filterOptionsRequestDto.getLevels().contains(generationList.getLevel())))
.collect(Collectors.toList());

// MemberResponseDto 생성
return MemberResponseDto.builder()
.member(member)
Expand All @@ -61,12 +67,17 @@ private List<GenerationResponseDto> createGenerationResponseDtoList(Member membe
// 해당 멤버 Generation
List<Generation> generationList = generationRepository.findByMember(member);
return generationList.stream()
.filter(generation ->
(filterOptionsRequestDto.getDepartments().isEmpty() || filterOptionsRequestDto.getDepartments().contains(generation.getDepartment())) &&
(filterOptionsRequestDto.getLevels().isEmpty() || filterOptionsRequestDto.getLevels().contains(generation.getLevel()))) // Filter based on department and level
/*.filter(generation ->
(filterOptionsRequestDto.getDepartments().isEmpty() || filterOptionsRequestDto.getDepartments().contains(generation.getDepartment())) ||
(filterOptionsRequestDto.getLevels().isEmpty() || filterOptionsRequestDto.getLevels().contains(generation.getLevel()))) */// Filter based on department and level
.map(generation -> {
// projectResponseDtoList 만들기 위해서 함수 호출
List<ProjectResponseDto> projectResponseDtoList = createProjectResponseDtoList(member, generation, filterOptionsRequestDto);
// 필터링
projectResponseDtoList=projectResponseDtoList.stream()
.filter(projectList -> (filterOptionsRequestDto.getParts().isEmpty() || filterOptionsRequestDto.getParts().contains(projectList.getPart())))
.collect(Collectors.toList());

// GenerationResponseDto 생성
return GenerationResponseDto.builder()
.generation(generation)
Expand All @@ -84,8 +95,8 @@ private List<ProjectResponseDto> createProjectResponseDtoList(Member member, Gen
return projects.stream()
// 중복된 part가 있으면 그 project 는 제외
// 필터링 조건 있다면 조건 부합하지 않는 project 제외
.filter(project -> existingParts.add(project.getPart())&&
(filterOptionsRequestDto.getParts().isEmpty() || filterOptionsRequestDto.getParts().contains(project.getPart()))) // Filter based on parts
.filter(project -> existingParts.add(project.getPart()))
/*(filterOptionsRequestDto.getParts().isEmpty() || filterOptionsRequestDto.getParts().contains(project.getPart())))*/ // Filter based on parts
.map(ProjectResponseDto::new)
.collect(Collectors.toList());
}
Expand Down

0 comments on commit d5b949b

Please sign in to comment.