diff --git a/src/main/java/com/yello/server/domain/friend/repository/FriendJpaRepository.java b/src/main/java/com/yello/server/domain/friend/repository/FriendJpaRepository.java index 86aa4804..e4b7deaf 100644 --- a/src/main/java/com/yello/server/domain/friend/repository/FriendJpaRepository.java +++ b/src/main/java/com/yello/server/domain/friend/repository/FriendJpaRepository.java @@ -29,7 +29,8 @@ Optional findByUserAndTarget(@Param("userId") Long userId, @Query("select f from Friend f " + "where f.target.id = :targetId " + "and f.user.id = :userId") - Optional findByUserAndTargetNotFiltered(@Param("userId") Long userId, @Param("targetId") Long targetId); + Optional findByUserAndTargetNotFiltered(@Param("userId") Long userId, + @Param("targetId") Long targetId); @Query("select case when count(f) > 0 then true else false end from Friend f " + "where f.target.id = :targetId " + @@ -64,4 +65,12 @@ Optional findByUserAndTarget(@Param("userId") Long userId, @Query("select f from Friend f " + "where f.target.id = :targetId") List findAllByTargetIdNotFiltered(@Param("targetId") Long targetId); + + @Query("select f from Friend f " + + "where f.user.id = :userId " + + "and f.target.uuid not in :uuidList " + + "and f.user.deletedAt is null " + + "and f.target.deletedAt is null") + List findALlByUserIdAndTargetNotIn(@Param("userId") Long userId, + @Param("uuidList") List uuidList); } diff --git a/src/main/java/com/yello/server/domain/friend/repository/FriendRepository.java b/src/main/java/com/yello/server/domain/friend/repository/FriendRepository.java index 731c70cc..39f5a3f4 100644 --- a/src/main/java/com/yello/server/domain/friend/repository/FriendRepository.java +++ b/src/main/java/com/yello/server/domain/friend/repository/FriendRepository.java @@ -31,4 +31,6 @@ public interface FriendRepository { List findAllByUserIdNotFiltered(Long userId); List findAllByTargetIdNotFiltered(Long targetId); + + List findAllByUserIdNotIn(Long userId, List uuidList); } diff --git a/src/main/java/com/yello/server/domain/friend/repository/FriendRepositoryImpl.java b/src/main/java/com/yello/server/domain/friend/repository/FriendRepositoryImpl.java index 26c79eb9..cfe74415 100644 --- a/src/main/java/com/yello/server/domain/friend/repository/FriendRepositoryImpl.java +++ b/src/main/java/com/yello/server/domain/friend/repository/FriendRepositoryImpl.java @@ -81,4 +81,9 @@ public List findAllByUserIdNotFiltered(Long userId) { public List findAllByTargetIdNotFiltered(Long targetId) { return friendJpaRepository.findAllByTargetIdNotFiltered(targetId); } + + @Override + public List findAllByUserIdNotIn(Long userId, List uuidList) { + return friendJpaRepository.findALlByUserIdAndTargetNotIn(userId, uuidList); + } } diff --git a/src/main/java/com/yello/server/domain/vote/service/VoteManagerImpl.java b/src/main/java/com/yello/server/domain/vote/service/VoteManagerImpl.java index 55a8210a..f857dfd4 100644 --- a/src/main/java/com/yello/server/domain/vote/service/VoteManagerImpl.java +++ b/src/main/java/com/yello/server/domain/vote/service/VoteManagerImpl.java @@ -29,6 +29,7 @@ import com.yello.server.domain.vote.exception.VoteNotFoundException; import com.yello.server.domain.vote.repository.VoteRepository; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random; @@ -90,20 +91,14 @@ public List generateVoteQuestion(User user, List questionList = new ArrayList<>(questions); Collections.shuffle(questionList); - return questions.stream() - .map(question -> { - final List keywords = question.getKeywordList(); - List keywordList = new ArrayList<>(keywords); - Collections.shuffle(keywordList); - - return QuestionForVoteResponse.builder() - .friendList(getShuffledFriends(user)) - .keywordList(getShuffledKeywords(question)) - .question(QuestionVO.of(question)) - .questionPoint(randomPoint()) - .subscribe(user.getSubscribe().toString()) - .build(); - }) + return questionList.stream() + .map(question -> QuestionForVoteResponse.builder() + .friendList(getShuffledFriends(user)) + .keywordList(getShuffledKeywords(question)) + .question(QuestionVO.of(question)) + .questionPoint(randomPoint()) + .subscribe(user.getSubscribe().toString()) + .build()) .limit(VOTE_COUNT) .toList(); } @@ -114,7 +109,7 @@ public int useNameHint(User sender, Vote vote) { throw new VoteForbiddenException(LACK_POINT_EXCEPTION); } - if (vote.getNameHint()!=NAME_HINT_DEFAULT) { + if (vote.getNameHint() != NAME_HINT_DEFAULT) { throw new VoteNotFoundException(INVALID_VOTE_EXCEPTION); } @@ -126,7 +121,7 @@ public int useNameHint(User sender, Vote vote) { @Override public KeywordCheckResponse useKeywordHint(User user, Vote vote) { - if (user.getSubscribe()!=Subscribe.NORMAL) { + if (user.getSubscribe() != Subscribe.NORMAL) { vote.checkKeyword(); } else { if (user.getPoint() < KEYWORD_HINT_POINT) { @@ -166,7 +161,9 @@ private boolean isDuplicatedVote(int index, List voteAnswers) { } private List getShuffledFriends(User user) { - final List friends = friendRepository.findAllByUserId(user.getId()); + List uuidList = Arrays.asList("yello_female", "yello_male"); + final List friends = friendRepository.findAllByUserIdNotIn(user.getId(), uuidList); + List friendList = new ArrayList<>(friends); Collections.shuffle(friendList); diff --git a/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java b/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java index 1ae56d1f..dfac562b 100644 --- a/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java +++ b/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java @@ -42,7 +42,8 @@ public void delete(Friend friend) { @Override public Integer countAllByUserId(Long userId) { return data.stream() - .filter(friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt() == null) + .filter( + friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt() == null) .toList() .size(); } @@ -50,7 +51,8 @@ public Integer countAllByUserId(Long userId) { @Override public Optional findByUserAndTarget(Long userId, Long targetId) { return data.stream() - .filter(friend -> friend.getUser().getId().equals(userId) && friend.getTarget().getId().equals(targetId) + .filter(friend -> friend.getUser().getId().equals(userId) && friend.getTarget().getId() + .equals(targetId) && friend.getDeletedAt() == null) .findFirst(); } @@ -58,7 +60,8 @@ public Optional findByUserAndTarget(Long userId, Long targetId) { @Override public Optional findByUserAndTargetNotFiltered(Long userId, Long targetId) { return data.stream() - .filter(friend -> friend.getUser().getId().equals(userId) && friend.getTarget().getId().equals(targetId)) + .filter(friend -> friend.getUser().getId().equals(userId) && friend.getTarget().getId() + .equals(targetId)) .findFirst(); } @@ -83,7 +86,8 @@ public boolean existsByUserAndTarget(Long userId, Long targetId) { @Override public Page findAllFriendsByUserId(Pageable pageable, Long userId) { final List friends = data.stream() - .filter(friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt() == null) + .filter( + friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt() == null) .toList(); final int start = (int) pageable.getOffset(); @@ -94,7 +98,8 @@ public Page findAllFriendsByUserId(Pageable pageable, Long userId) { @Override public List findAllByUserId(Long userId) { return data.stream() - .filter(friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt() == null) + .filter( + friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt() == null) .toList(); } @@ -102,7 +107,8 @@ public List findAllByUserId(Long userId) { public List findAllByTargetId(Long targetId) { return data.stream() .filter( - friend -> friend.getTarget().getId().equals(targetId) && friend.getDeletedAt() == null) + friend -> friend.getTarget().getId().equals(targetId) + && friend.getDeletedAt() == null) .toList(); } @@ -119,4 +125,12 @@ public List findAllByTargetIdNotFiltered(Long targetId) { .filter(friend -> friend.getTarget().getId().equals(targetId)) .toList(); } + + @Override + public List findAllByUserIdNotIn(Long userId, List uuidList) { + return data.stream() + .filter(friend -> friend.getUser().getId().equals(userId)) + .filter(friend -> !uuidList.contains(friend.getTarget().getYelloId())) + .toList(); + } }