diff --git a/src/main/java/org/sopt/app/application/friend/FriendRecommender.java b/src/main/java/org/sopt/app/application/friend/FriendRecommender.java index 8827e265..55990ddc 100644 --- a/src/main/java/org/sopt/app/application/friend/FriendRecommender.java +++ b/src/main/java/org/sopt/app/application/friend/FriendRecommender.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.Set; import lombok.RequiredArgsConstructor; import org.sopt.app.application.playground.PlaygroundAuthService; @@ -24,7 +25,8 @@ public class FriendRecommender { private final FriendService friendService; private final PlaygroundUserIdsProvider playgroundUserIdsProvider; - public RecommendedFriendsRequest recommendFriendsByTypeList(List typeList, int size, User user) { + public RecommendedFriendsRequest recommendFriendsByTypeList(List typeList, int size, + User user) { typeList = this.adjustTypeList(typeList); OwnPlaygroundProfile ownProfile = playgroundAuthService.getOwnPlaygroundProfile(user.getPlaygroundToken()); @@ -58,22 +60,17 @@ private List convertUserProfilesToSimplePokeProfiles( } private List makeSimplePokeProfilesForNotFriend( - List playgroundProfiles, List userProfiles) { - - return userProfiles.stream().map(userProfile -> { - PlaygroundProfile playgroundProfile = playgroundProfiles.stream() - .filter(profile -> profile.getMemberId().equals(userProfile.getPlaygroundId())) - .findFirst().orElseThrow(); - - return SimplePokeProfile.createNonFriendPokeProfile( - userProfile.getUserId(), - userProfile.getPlaygroundId(), - playgroundProfile.getProfileImage(), - userProfile.getName(), - playgroundProfile.getLatestActivity().getGeneration(), - playgroundProfile.getLatestActivity().getPlaygroundPart().getPartName() - ); - }).toList(); + List playgroundProfiles, List userProfiles + ) { + return userProfiles.stream() + .map(userProfile -> playgroundProfiles.stream() + .filter(profile -> profile.getMemberId().equals(userProfile.getPlaygroundId())) + .findFirst() + .map(playgroundProfile -> + SimplePokeProfile.createNonFriendPokeProfile(playgroundProfile, userProfile)) + ) + .filter(Optional::isPresent).map(Optional::get) + .toList(); } private List getRecommendableUserProfiles( @@ -84,7 +81,8 @@ private List getRecommendableUserProfiles( } else { playgroundIds = playgroundUserIdsProvider.findPlaygroundIdsByType(ownProfile, type); } - List unFilteredUserProfiles = userService.getUserProfilesByPlaygroundIds(List.copyOf(playgroundIds)); + List unFilteredUserProfiles = userService.getUserProfilesByPlaygroundIds( + List.copyOf(playgroundIds)); return friendFilter.excludeAlreadyFriendUserIds(unFilteredUserProfiles); } diff --git a/src/main/java/org/sopt/app/presentation/poke/PokeResponse.java b/src/main/java/org/sopt/app/presentation/poke/PokeResponse.java index c3e11bf9..1de3e9c6 100755 --- a/src/main/java/org/sopt/app/presentation/poke/PokeResponse.java +++ b/src/main/java/org/sopt/app/presentation/poke/PokeResponse.java @@ -3,7 +3,9 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import lombok.*; +import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile; import org.sopt.app.application.poke.PokeInfo.*; +import org.sopt.app.application.user.UserProfile; import org.sopt.app.domain.enums.FriendRecommendType; import org.sopt.app.common.utils.AnonymousImageGenerator; @@ -196,21 +198,16 @@ public static SimplePokeProfile of( } public static SimplePokeProfile createNonFriendPokeProfile( - Long userId, - Long playgroundId, - String profileImage, - String name, - Long generation, - String part + PlaygroundProfile playgroundProfile, UserProfile userProfile ) { return new SimplePokeProfile( - userId, - playgroundId, - profileImage == null ? "" : profileImage, - name, + userProfile.getUserId(), + userProfile.getPlaygroundId(), + playgroundProfile.getProfileImage() == null ? "" : playgroundProfile.getProfileImage(), + userProfile.getName(), "", - generation, - part, + playgroundProfile.getLatestActivity().getGeneration(), + playgroundProfile.getLatestActivity().getPlaygroundPart().getPartName(), 0, "", "",