Skip to content

Commit

Permalink
YEL-32 [develop] 투표리스트 옐로팀 제외
Browse files Browse the repository at this point in the history
YEL-32 [develop] 투표리스트 옐로팀 제외
  • Loading branch information
hyeonjeongs authored Aug 20, 2023
2 parents 08925eb + 5ecd34b commit 4a01ad6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Optional<Friend> findByUserAndTarget(@Param("userId") Long userId,
@Query("select f from Friend f " +
"where f.target.id = :targetId " +
"and f.user.id = :userId")
Optional<Friend> findByUserAndTargetNotFiltered(@Param("userId") Long userId, @Param("targetId") Long targetId);
Optional<Friend> 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 " +
Expand Down Expand Up @@ -64,4 +65,12 @@ Optional<Friend> findByUserAndTarget(@Param("userId") Long userId,
@Query("select f from Friend f " +
"where f.target.id = :targetId")
List<Friend> 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<Friend> findALlByUserIdAndTargetNotIn(@Param("userId") Long userId,
@Param("uuidList") List<String> uuidList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface FriendRepository {
List<Friend> findAllByUserIdNotFiltered(Long userId);

List<Friend> findAllByTargetIdNotFiltered(Long targetId);

List<Friend> findAllByUserIdNotIn(Long userId, List<String> uuidList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public List<Friend> findAllByUserIdNotFiltered(Long userId) {
public List<Friend> findAllByTargetIdNotFiltered(Long targetId) {
return friendJpaRepository.findAllByTargetIdNotFiltered(targetId);
}

@Override
public List<Friend> findAllByUserIdNotIn(Long userId, List<String> uuidList) {
return friendJpaRepository.findALlByUserIdAndTargetNotIn(userId, uuidList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,20 +91,14 @@ public List<QuestionForVoteResponse> generateVoteQuestion(User user, List<Questi
List<Question> questionList = new ArrayList<>(questions);
Collections.shuffle(questionList);

return questions.stream()
.map(question -> {
final List<Keyword> keywords = question.getKeywordList();
List<Keyword> 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();
}
Expand All @@ -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);
}

Expand All @@ -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) {
Expand Down Expand Up @@ -166,7 +161,9 @@ private boolean isDuplicatedVote(int index, List<VoteAnswer> voteAnswers) {
}

private List<FriendShuffleResponse> getShuffledFriends(User user) {
final List<Friend> friends = friendRepository.findAllByUserId(user.getId());
List<String> uuidList = Arrays.asList("yello_female", "yello_male");
final List<Friend> friends = friendRepository.findAllByUserIdNotIn(user.getId(), uuidList);

List<Friend> friendList = new ArrayList<>(friends);
Collections.shuffle(friendList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,26 @@ 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();
}

@Override
public Optional<Friend> 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();
}

@Override
public Optional<Friend> 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();
}

Expand All @@ -83,7 +86,8 @@ public boolean existsByUserAndTarget(Long userId, Long targetId) {
@Override
public Page<Friend> findAllFriendsByUserId(Pageable pageable, Long userId) {
final List<Friend> 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();
Expand All @@ -94,15 +98,17 @@ public Page<Friend> findAllFriendsByUserId(Pageable pageable, Long userId) {
@Override
public List<Friend> 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();
}

@Override
public List<Friend> 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();
}

Expand All @@ -119,4 +125,12 @@ public List<Friend> findAllByTargetIdNotFiltered(Long targetId) {
.filter(friend -> friend.getTarget().getId().equals(targetId))
.toList();
}

@Override
public List<Friend> findAllByUserIdNotIn(Long userId, List<String> uuidList) {
return data.stream()
.filter(friend -> friend.getUser().getId().equals(userId))
.filter(friend -> !uuidList.contains(friend.getTarget().getYelloId()))
.toList();
}
}

0 comments on commit 4a01ad6

Please sign in to comment.