From 13bc1c8d579551df3b176a92d15befd9e4133ef1 Mon Sep 17 00:00:00 2001 From: hyeonjeongs Date: Sun, 20 Aug 2023 17:58:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?YEL-131=20[fix]=20random=20=ED=88=AC?= =?UTF-8?q?=ED=91=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/vote/service/VoteManagerImpl.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) 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..3a9d2308 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 @@ -90,20 +90,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 +108,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 +120,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) { From 73d7992bd948a3f25e6f5aa467641f0646afa330 Mon Sep 17 00:00:00 2001 From: hyeonjeongs Date: Sun, 20 Aug 2023 19:26:25 +0900 Subject: [PATCH 2/2] =?UTF-8?q?YEL-131=20[fix]=20test=20repository=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/friend/FakeFriendRepository.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) 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(); + } }