Skip to content

Commit

Permalink
refactor: Rename fields on MemberResponseDto (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nusuy committed Dec 14, 2023
1 parent 9f6f7e8 commit 96c1615
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ public class GenerationResponseDto {
private Integer number; // 기수 (1기, 2기...)
private String department; // 부서 (안드, UX/UI...)
private String level; // 레벨 (코어, 리드...)
private List<ProjectResponseDto> projectResponseDtoList;
private List<ProjectResponseDto> projectList;

@Builder
public GenerationResponseDto(Generation generation, List<ProjectResponseDto> projectResponseDtoList) {
public GenerationResponseDto(Generation generation, List<ProjectResponseDto> projectList) {
this.number = generation.getNumber();
this.department = generation.getDepartment();
this.level = generation.getLevel();
this.projectResponseDtoList = projectResponseDtoList;
this.projectList = projectList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public class MemberResponseDto {
private Integer admissionYear; // 학번
private String profileImagePath; // 프로필 사진
private boolean bookmark; // 북마크 저장 여부
private List<GenerationResponseDto> generationResponseDtoList;
private List<GenerationResponseDto> generationList;

@Builder
public MemberResponseDto(Member member, boolean bookmark, List<GenerationResponseDto> generationResponseDtoList) {
public MemberResponseDto(Member member, boolean bookmark, List<GenerationResponseDto> generationList) {
this.name = member.getName();
this.profileImagePath = member.getProfileImagePath();
this.major = member.getMajor();
this.admissionYear = member.getAdmissionYear();
this.bookmark = bookmark;
this.generationResponseDtoList = generationResponseDtoList;
this.generationList = generationList;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.apache.logging.log4j.ThreadContext.isEmpty;

@RequiredArgsConstructor
@Service
public class NetworkService {
Expand All @@ -40,14 +38,15 @@ public ResponseEntity<Object> findAllMembers(FilterOptionsRequestDto filterOptio
return memberResponseDto;
})
.collect(Collectors.toList());
memberResponseDtoList=memberResponseDtoList.stream().filter(filteredMembers -> isMemberMatch(filteredMembers, filterOptionsRequestDto)).collect(Collectors.toList());
return ResponseEntity.ok(memberResponseDtoList);
memberResponseDtoList = memberResponseDtoList.stream().filter(filteredMembers -> isMemberMatch(filteredMembers, filterOptionsRequestDto)).collect(Collectors.toList());
return ResponseEntity.ok(memberResponseDtoList);
} catch (Exception e) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@Transactional
private boolean isMemberMatch(MemberResponseDto filteredMembers,FilterOptionsRequestDto filterOptionsRequestDto) {
private boolean isMemberMatch(MemberResponseDto filteredMembers, FilterOptionsRequestDto filterOptionsRequestDto) {
// 셋다 true 여야 return 해주는 로직
boolean partMatch;
boolean levelMatch;
Expand All @@ -56,20 +55,20 @@ private boolean isMemberMatch(MemberResponseDto filteredMembers,FilterOptionsReq
// containsAll 메서드는 파라미터로 전달된 컬렉션이 비어있으면 무조건 true 를 반환
// 조건이 없으면 다 true 처리 함 (어차피 다른 조건 안맞으면 못 나감)
partMatch =
filteredMembers.getGenerationResponseDtoList().stream()
.flatMap(generationResponseDto -> generationResponseDto.getProjectResponseDtoList().stream())
filteredMembers.getGenerationList().stream()
.flatMap(generationResponseDto -> generationResponseDto.getProjectList().stream())
.map(ProjectResponseDto::getPart)
.collect(Collectors.toList())
// filteredMembers 의 part 조건이 filterOptionsRequestDto 의 모든 조건을 포함하고 있는지 확인
// 필터링을 하고자 하는 조건을 멤버가 전부 가져야 함
.containsAll(filterOptionsRequestDto.getParts());
levelMatch =
filteredMembers.getGenerationResponseDtoList().stream()
filteredMembers.getGenerationList().stream()
.map(GenerationResponseDto::getLevel)
.collect(Collectors.toList())
.containsAll(filterOptionsRequestDto.getLevels());
departmentMatch =
filteredMembers.getGenerationResponseDtoList().stream()
filteredMembers.getGenerationList().stream()
.map(GenerationResponseDto::getDepartment)
.collect(Collectors.toList())
.containsAll(filterOptionsRequestDto.getDepartments());
Expand Down Expand Up @@ -125,7 +124,7 @@ private MemberResponseDto createMemberResponseDto(Member member, FilterOptionsRe
return MemberResponseDto.builder()
.member(member)
.bookmark(bookmark)
.generationResponseDtoList(generationResponseDtoList)
.generationList(generationResponseDtoList)
.build();
}

Expand All @@ -140,11 +139,12 @@ private List<GenerationResponseDto> createGenerationResponseDtoList(Member membe
// GenerationResponseDto 생성
return GenerationResponseDto.builder()
.generation(generation)
.projectResponseDtoList(projectResponseDtoList)
.projectList(projectResponseDtoList)
.build();
})
.collect(Collectors.toList());
}

@Transactional
private List<ProjectResponseDto> createProjectResponseDtoList(Member member, Generation generation, FilterOptionsRequestDto filterOptionsRequestDto) {
List<Project> projects = projectRepository.findByMemberAndGeneration(member, generation);
Expand All @@ -157,7 +157,6 @@ private List<ProjectResponseDto> createProjectResponseDtoList(Member member, Gen
}



@Transactional
public ResponseEntity<Object> bookmarkMember(Long memberIdToBookmark) {
try {
Expand All @@ -174,7 +173,7 @@ public ResponseEntity<Object> bookmarkMember(Long memberIdToBookmark) {
}
return ResponseEntity.ok(bookmarkRepository.existsByTargetMemberId(memberIdToBookmark));

} catch (Exception e){
} catch (Exception e) {
return ResponseEntity.badRequest().body(e.getMessage());
}

Expand Down

0 comments on commit 96c1615

Please sign in to comment.