Skip to content

Commit

Permalink
[COZY-445] refac: 방 일치율 계산 로직을 메서드 추출한다
Browse files Browse the repository at this point in the history
  • Loading branch information
veronees committed Dec 5, 2024
1 parent 53ffc6c commit 87664e8
Showing 1 changed file with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,29 @@ public PageResponseDto<List<RoomRecommendationResponseDTO>> getRecommendationLis
EntryStatus.JOINED)
.stream().collect(Collectors.groupingBy(mate -> mate.getRoom().getId()));

HashMap<Long, Integer> roomEqualityMap = new HashMap<>();
Map<Long, Integer> roomEqualityMap = calculateRoomEqualityMap(roomList, roomMateMap,
member);

// null을 가장 후순위로 처리
List<Pair<Long, Integer>> sortedRoomList = getSortedRoomListBySortType(roomEqualityMap,
roomMap, sortType, page, size);
boolean hasNext = sortedRoomList.size() > size;
sortedRoomList = sortedRoomList.stream().limit(size).toList();

List<RoomRecommendationResponseDTO> roomRecommendationResponseDTOList = buildRoomRecommendationResponseList(
member, sortedRoomList, roomMateMap, roomList, memberPreferenceList);

return PageResponseDto.<List<RoomRecommendationResponseDTO>>builder()
.page(page)
.hasNext(hasNext)
.result(roomRecommendationResponseDTOList)
.build();
}

private Map<Long, Integer> calculateRoomEqualityMap(List<Room> roomList,
Map<Long, List<Mate>> roomMateMap, Member member) {

Map<Long, Integer> roomEqualityMap = new HashMap<>();

roomList.forEach(room -> {
List<Mate> mates = roomMateMap.get(room.getId());
Expand All @@ -85,20 +107,7 @@ public PageResponseDto<List<RoomRecommendationResponseDTO>> getRecommendationLis
roomEqualityMap.put(room.getId(), roomEquality);
});

// null을 가장 후순위로 처리
List<Pair<Long, Integer>> sortedRoomList = getSortedRoomListBySortType(roomEqualityMap,
roomMap, sortType, page, size);
boolean hasNext = sortedRoomList.size() > size;
sortedRoomList = sortedRoomList.stream().limit(size).toList();

List<RoomRecommendationResponseDTO> roomRecommendationResponseDTOList = buildRoomRecommendationResponseList(
member, sortedRoomList, roomMateMap, roomList, memberPreferenceList);

return PageResponseDto.<List<RoomRecommendationResponseDTO>>builder()
.page(page)
.hasNext(hasNext)
.result(roomRecommendationResponseDTOList)
.build();
return roomEqualityMap;
}

private List<RoomRecommendationResponseDTO> buildRoomRecommendationResponseList(
Expand Down

0 comments on commit 87664e8

Please sign in to comment.