Skip to content

Commit

Permalink
fix: 친구를 찔러보세요 - 친구 관계 변경 로직 대응 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunom authored Jan 8, 2024
2 parents 54dd145 + f0517eb commit c52ab4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/org/sopt/app/application/poke/FriendService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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 @@ -101,9 +102,18 @@ public List<Long> getMutualFriendIds(Long pokerId, Long pokedId) {
}

public List<Long> getPokeFriendIdRandomly(Long userId) {
List<Long> pokeFriendIds = friendRepository.findAllOfFriendIdsByUserId(userId);
Collections.shuffle(pokeFriendIds);
return pokeFriendIds.subList(0, 1);
val friendIdsPokeMe = friendRepository.findAllByFriendUserId(userId).stream()
.map(Friend::getUserId)
.toList();
val friendIds = friendRepository.findAllByUserIdAndFriendUserIdIn(userId, friendIdsPokeMe).stream().map(
Friend::getFriendUserId
).toList();

if(friendIds.isEmpty()) {
return friendIds;
}
Collections.shuffle(friendIds);
return friendIds.subList(0, 1);
}

public List<Long> findAllFriendIdsByUserIdRandomlyExcludeUserId(Long friendsUserId, List<Long> excludedUserId, int limitNum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public interface FriendRepository extends JpaRepository<Friend, Long>, FriendCus

@Query("SELECT f.friendUserId FROM Friend f WHERE f.userId = :userId")
List<Long> findAllOfFriendIdsByUserId(@Param("userId") Long userId);

List<Friend> findAllByFriendUserId(Long friendUserId);

@Query(value = "SELECT f FROM Friend f WHERE f.userId = :userId AND f.pokeCount BETWEEN :lowerLimit AND :upperLimit ORDER BY f.pokeCount")
List<Friend> findAllByUserIdAndPokeCountBetweenOrderByPokeCountDesc(@Param("userId") Long userId, @Param("lowerLimit") Integer lowerLimit, @Param("upperLimit") Integer upperLimit);
@Query(value = "SELECT f FROM Friend f WHERE f.userId = :userId AND f.pokeCount BETWEEN :lowerLimit AND :upperLimit ORDER BY f.pokeCount")
Expand All @@ -24,4 +27,6 @@ public interface FriendRepository extends JpaRepository<Friend, Long>, FriendCus
int findSizeByUserIdAndPokeCountBetween(Long userId, Integer lowerLimit, Integer upperLimit);

List<Friend> findAllByUserId(Long userId);

List<Friend> findAllByUserIdAndFriendUserIdIn(Long userId, List<Long> friendIdsPokeMe);
}

0 comments on commit c52ab4a

Please sign in to comment.