From 9f1b88130e82c9b788e2fd21e1435d76811bed6e Mon Sep 17 00:00:00 2001 From: gunom Date: Sat, 23 Dec 2023 21:15:22 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=82=A0=20=EC=B0=8C=EB=A5=B8=20?= =?UTF-8?q?=EC=B9=9C=EA=B5=AC=20=EB=B6=88=EB=9F=AC=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/app/application/poke/FriendService.java | 12 +++++------- src/main/java/org/sopt/app/facade/PokeFacade.java | 11 +++++------ .../app/interfaces/postgres/FriendRepository.java | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/sopt/app/application/poke/FriendService.java b/src/main/java/org/sopt/app/application/poke/FriendService.java index c9b2607c..515b4cec 100644 --- a/src/main/java/org/sopt/app/application/poke/FriendService.java +++ b/src/main/java/org/sopt/app/application/poke/FriendService.java @@ -1,10 +1,8 @@ package org.sopt.app.application.poke; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import lombok.RequiredArgsConstructor; -import lombok.val; import org.sopt.app.common.exception.NotFoundException; import org.sopt.app.common.response.ErrorCode; import org.sopt.app.domain.entity.Friend; @@ -95,12 +93,12 @@ public List getMutualFriendIds(Long pokerId, Long pokedId) { .toList(); } - public List getNotPokeFriendIdRandomly(Long userId, List pokedFriendIds) { - List notPokeFriendIds = friendRepository.findAllByUserIdAndFriendUserIdNotInAndFriendUserIdNotIn(userId, pokedFriendIds); - Collections.shuffle(notPokeFriendIds); - if (notPokeFriendIds.isEmpty()) { + public List getPokeFriendIdRandomly(Long userId, List pokeUserIds) { + List pokeFriendIds = friendRepository.findAllByUserIdAndFriendUserIdNotIn(userId, pokeUserIds); + Collections.shuffle(pokeFriendIds); + if (pokeFriendIds.isEmpty()) { return List.of(); } - return notPokeFriendIds.subList(0, 1); + return pokeFriendIds.subList(0, 1); } } diff --git a/src/main/java/org/sopt/app/facade/PokeFacade.java b/src/main/java/org/sopt/app/facade/PokeFacade.java index a17a8dc8..a321234a 100644 --- a/src/main/java/org/sopt/app/facade/PokeFacade.java +++ b/src/main/java/org/sopt/app/facade/PokeFacade.java @@ -95,14 +95,13 @@ private List pickRandomUserIds( @Transactional(readOnly = true) public List getRecommendFriendsOfUsersFriend(User user) { - val userId = user.getId(); - val friendsUserIds = friendService.findAllFriendIdsByUserIdRandomly(userId, 2); + val friendsUserIds = friendService.findAllFriendIdsByUserIdRandomly(user.getId(), 2); return friendsUserIds.stream().map( friendsUserId -> { val friendUser = userService.getUserProfile(friendsUserId); val friendProfile = playgroundAuthService.getPlaygroundMemberProfiles(user.getPlaygroundToken() ,List.of( friendUser.getPlaygroundId())).get(0); - val recommendUserProfiles = userService.findRandomFriendsOfFriends(userId, friendsUserId, 2); + val recommendUserProfiles = userService.findRandomFriendsOfFriends(user.getId(), friendsUserId, 2); val playgroundProfiles = playgroundAuthService.getPlaygroundMemberProfiles(user.getPlaygroundToken(), recommendUserProfiles.stream().map(UserProfile::getPlaygroundId).toList()); val simpleProfiles = makeDummySimplePokeProfile(recommendUserProfiles, playgroundProfiles); return PokeResponse.Friend.of( @@ -170,10 +169,10 @@ private void applyFriendship(Long pokerUserId, Long pokedUserId) { @Transactional(readOnly = true) public List getFriend(User user) { - val pokedFriendIds = pokeHistoryService.getPokedFriendIds(user.getId()); - val friendId = friendService.getNotPokeFriendIdRandomly( + val pokeUserIds = pokeHistoryService.getPokeFriendIds(user.getId()); + val friendId = friendService.getPokeFriendIdRandomly( user.getId(), - pokedFriendIds); + pokeUserIds); if (friendId.isEmpty()) { return List.of(); } diff --git a/src/main/java/org/sopt/app/interfaces/postgres/FriendRepository.java b/src/main/java/org/sopt/app/interfaces/postgres/FriendRepository.java index a10c0e4c..92b6b118 100644 --- a/src/main/java/org/sopt/app/interfaces/postgres/FriendRepository.java +++ b/src/main/java/org/sopt/app/interfaces/postgres/FriendRepository.java @@ -13,8 +13,8 @@ public interface FriendRepository extends JpaRepository, FriendCustomRepository { Optional findByUserIdAndFriendUserId(Long userId, Long friendId); - @Query(value = "SELECT f.friendUserId FROM Friend as f WHERE f.userId = :userId AND f.friendUserId NOT IN (:pokedFriendIds)") - List findAllByUserIdAndFriendUserIdNotInAndFriendUserIdNotIn(@Param("userId") Long userId, @Param("pokedFriendIds") List pokedFriendIds); + @Query(value = "SELECT f.friendUserId FROM Friend as f WHERE f.userId = :userId AND f.friendUserId IN (:pokeUserIds)") + List findAllByUserIdAndFriendUserIdNotIn(@Param("userId") Long userId, @Param("pokeUserIds") List pokeUserIds); @Query("SELECT f.friendUserId FROM Friend f WHERE f.userId = :userId") List findAllOfFriendIdsByUserId(@Param("userId") Long userId); @Query(value = "SELECT f FROM Friend f WHERE f.userId = :userId AND f.pokeCount BETWEEN :lowerLimit AND :upperLimit ORDER BY f.pokeCount")