From 87664e8a88993df4a1d39471e756499d6d43b702 Mon Sep 17 00:00:00 2001 From: veronees Date: Fri, 6 Dec 2024 05:03:25 +0900 Subject: [PATCH] =?UTF-8?q?[COZY-445]=20refac:=20=EB=B0=A9=20=EC=9D=BC?= =?UTF-8?q?=EC=B9=98=EC=9C=A8=20=EA=B3=84=EC=82=B0=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=84=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EC=B6=9C?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../room/service/RoomRecommendService.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/cozymate/cozymate_server/domain/room/service/RoomRecommendService.java b/src/main/java/com/cozymate/cozymate_server/domain/room/service/RoomRecommendService.java index f0093f67..94a6ed1c 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/room/service/RoomRecommendService.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/room/service/RoomRecommendService.java @@ -68,7 +68,29 @@ public PageResponseDto> getRecommendationLis EntryStatus.JOINED) .stream().collect(Collectors.groupingBy(mate -> mate.getRoom().getId())); - HashMap roomEqualityMap = new HashMap<>(); + Map roomEqualityMap = calculateRoomEqualityMap(roomList, roomMateMap, + member); + + // null을 가장 후순위로 처리 + List> sortedRoomList = getSortedRoomListBySortType(roomEqualityMap, + roomMap, sortType, page, size); + boolean hasNext = sortedRoomList.size() > size; + sortedRoomList = sortedRoomList.stream().limit(size).toList(); + + List roomRecommendationResponseDTOList = buildRoomRecommendationResponseList( + member, sortedRoomList, roomMateMap, roomList, memberPreferenceList); + + return PageResponseDto.>builder() + .page(page) + .hasNext(hasNext) + .result(roomRecommendationResponseDTOList) + .build(); + } + + private Map calculateRoomEqualityMap(List roomList, + Map> roomMateMap, Member member) { + + Map roomEqualityMap = new HashMap<>(); roomList.forEach(room -> { List mates = roomMateMap.get(room.getId()); @@ -85,20 +107,7 @@ public PageResponseDto> getRecommendationLis roomEqualityMap.put(room.getId(), roomEquality); }); - // null을 가장 후순위로 처리 - List> sortedRoomList = getSortedRoomListBySortType(roomEqualityMap, - roomMap, sortType, page, size); - boolean hasNext = sortedRoomList.size() > size; - sortedRoomList = sortedRoomList.stream().limit(size).toList(); - - List roomRecommendationResponseDTOList = buildRoomRecommendationResponseList( - member, sortedRoomList, roomMateMap, roomList, memberPreferenceList); - - return PageResponseDto.>builder() - .page(page) - .hasNext(hasNext) - .result(roomRecommendationResponseDTOList) - .build(); + return roomEqualityMap; } private List buildRoomRecommendationResponseList(