Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 날 찌른 친구 불러오는 로직 수정 #187

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/main/java/org/sopt/app/application/poke/FriendService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -95,12 +93,12 @@ public List<Long> getMutualFriendIds(Long pokerId, Long pokedId) {
.toList();
}

public List<Long> getNotPokeFriendIdRandomly(Long userId, List<Long> pokedFriendIds) {
List<Long> notPokeFriendIds = friendRepository.findAllByUserIdAndFriendUserIdNotInAndFriendUserIdNotIn(userId, pokedFriendIds);
Collections.shuffle(notPokeFriendIds);
if (notPokeFriendIds.isEmpty()) {
public List<Long> getPokeFriendIdRandomly(Long userId, List<Long> pokeUserIds) {
List<Long> pokeFriendIds = friendRepository.findAllByUserIdAndFriendUserIdNotIn(userId, pokeUserIds);
Collections.shuffle(pokeFriendIds);
if (pokeFriendIds.isEmpty()) {
return List.of();
}
return notPokeFriendIds.subList(0, 1);
return pokeFriendIds.subList(0, 1);
}
}
11 changes: 5 additions & 6 deletions src/main/java/org/sopt/app/facade/PokeFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ private List<Long> pickRandomUserIds(

@Transactional(readOnly = true)
public List<PokeResponse.Friend> 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(
Expand Down Expand Up @@ -170,10 +169,10 @@ private void applyFriendship(Long pokerUserId, Long pokedUserId) {

@Transactional(readOnly = true)
public List<SimplePokeProfile> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
public interface FriendRepository extends JpaRepository<Friend, Long>, FriendCustomRepository {
Optional<Friend> 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<Long> findAllByUserIdAndFriendUserIdNotInAndFriendUserIdNotIn(@Param("userId") Long userId, @Param("pokedFriendIds") List<Long> pokedFriendIds);
@Query(value = "SELECT f.friendUserId FROM Friend as f WHERE f.userId = :userId AND f.friendUserId IN (:pokeUserIds)")
List<Long> findAllByUserIdAndFriendUserIdNotIn(@Param("userId") Long userId, @Param("pokeUserIds") List<Long> pokeUserIds);
@Query("SELECT f.friendUserId FROM Friend f WHERE f.userId = :userId")
List<Long> 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")
Expand Down