Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ public ApiResponse<SearchResponseDTO.GetCardListResponseDto> getCardsByHashtag(
return ApiResponse.onSuccess(result);
}

@Operation(summary = "해당 유저 팔로우 목록 조회", description = "팔로우 - 해시태그 검색 api")
@Operation(summary = "해당 유저 팔로잉,팔로워 검색", description = "FOLLOWING은 유저(userId)가 팔로우 중인 목록을, FOLLOWED는 유저를 팔로우하는 목록을 반환합니다." +
"<br> query가 null일 경우 임의의 팔로잉/팔로워 목록을 반환합니다")
@GetMapping("/followList")
public ApiResponse<SearchResponseDTO.GetAccountListResponseDtoWithFollow> searchFollowList(
HttpServletRequest request,
@RequestParam(value = "follow status")FollowStatus status,
@RequestParam(value = "userId")Long userId,
@RequestParam(value = "query") String query,
@RequestParam(value = "query", required = false) String query,
@RequestParam(value = "limit", required = false, defaultValue = "10") int limit,
@RequestParam(value = "cursor", required = false) Long cursor
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,16 @@ public SearchResponseDTO.GetAccountListResponseDtoWithFollow getFollowList(HttpS

User me = userService.getLoginUser(request);

if(query == null){

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

if(query == null) 블록은 비어 있어 아무런 동작도 하지 않습니다. 불필요한 코드이므로 제거하는 것이 좋습니다.

// 페이징 처리 하기
Pageable pageable = PageRequest.of(0, limit + 1, Sort.by("id").ascending());
Slice<User> users = new SliceImpl<>(Collections.emptyList(), pageable, false);
switch(status){
case FOLLOWED -> { // 해당 유저를 팔로우한 사람 목록
users = userRepository.searchAccountNotInFollow(query, cursor, pageable, userId);
users = userRepository.searchAccountInFollower(query, cursor, pageable, userId);
}
case FOLLOWING -> { // 해당 유저가 팔로우한 사람 목록
users = userRepository.searchAccountInFollow(query, cursor, pageable, userId);
Expand All @@ -234,12 +238,10 @@ public SearchResponseDTO.GetAccountListResponseDtoWithFollow getFollowList(HttpS
// 내가 팔로우한 유저 목록
Set<Long> alreadyFollowedIdSet = new HashSet<>(userFollowRepository.findFollowingUserIds(me.getId()));



List<SearchResponseDTO.GetAccountResponseDtoWithFollow> result = users.getContent().stream()
.map(user -> UserConverter.toAccountDtoWithFollow(
user,
alreadyFollowedIdSet.contains(user.getId()))
alreadyFollowedIdSet.contains(user.getId())) // 내 기준 팔로우 여부 표시
).toList();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,32 @@ Slice<User> searchAccountInAll(@Param("query") String query,
JOIN UserFollow uf ON u.id = uf.targetUser.id
WHERE uf.user.id = :loginUserId
AND (:cursor IS NULL OR u.id > :cursor)
AND (LOWER(u.nameId) LIKE LOWER(CONCAT(:query, '%'))
OR LOWER(u.nickname) LIKE LOWER(CONCAT(:query, '%')))
AND (:query IS NULL OR
LOWER(u.nameId) LIKE LOWER(CONCAT(:query, '%'))
OR LOWER(u.nickname) LIKE LOWER(CONCAT(:query, '%')))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

JPQL 쿼리에서 ANDOR 연산자의 우선순위 문제로 인해 논리적 오류가 발생할 수 있습니다. 현재 쿼리는 ... AND (:query IS NULL) OR (LOWER(u.nameId) ...) 와 같이 해석될 수 있어, query가 null이 아닐 경우 loginUserId 조건이 무시될 수 있습니다. OR 조건들을 괄호로 묶어 의도한 대로 동작하도록 수정해야 합니다.

Suggested change
AND (:query IS NULL OR
LOWER(u.nameId) LIKE LOWER(CONCAT(:query, '%'))
OR LOWER(u.nickname) LIKE LOWER(CONCAT(:query, '%')))
AND (:query IS NULL OR (LOWER(u.nameId) LIKE LOWER(CONCAT(:query, '%'))
OR LOWER(u.nickname) LIKE LOWER(CONCAT(:query, '%'))))

ORDER BY u.id ASC
""")
Slice<User> searchAccountInFollow(@Param("query") String query,
@Param("cursor") Long cursor,
Pageable pageable,
@Param("loginUserId") Long userId);

@Query("""
SELECT u
FROM User u
JOIN UserFollow uf ON u.id = uf.user.id
WHERE uf.targetUser.id = :loginUserId
AND (:cursor IS NULL OR u.id > :cursor)
AND (:query IS NULL OR
LOWER(u.nameId) LIKE LOWER(CONCAT(:query, '%'))
OR LOWER(u.nickname) LIKE LOWER(CONCAT(:query, '%')))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

searchAccountInFollow 쿼리와 마찬가지로, 이 쿼리에서도 ANDOR 연산자 우선순위로 인한 논리적 오류가 존재합니다. OR 조건들을 괄호로 묶어주세요.

Suggested change
AND (:query IS NULL OR
LOWER(u.nameId) LIKE LOWER(CONCAT(:query, '%'))
OR LOWER(u.nickname) LIKE LOWER(CONCAT(:query, '%')))
AND (:query IS NULL OR
(LOWER(u.nameId) LIKE LOWER(CONCAT(:query, '%'))
OR LOWER(u.nickname) LIKE LOWER(CONCAT(:query, '%'))))

ORDER BY u.id ASC
""")
Slice<User> searchAccountInFollower(@Param("query") String query,
@Param("cursor") Long cursor,
Pageable pageable,
@Param("loginUserId") Long userId);


// @Query("""
// SELECT u FROM User u
Expand All @@ -74,19 +91,5 @@ Slice<User> searchAccountInFollow(@Param("query") String query,
// @Param("loginUserId") Long userId);


@Query("""
SELECT u
FROM User u
WHERE u.id NOT IN (
SELECT uf.targetUser.id
FROM UserFollow uf
WHERE uf.user.id = :loginUserId
)
AND (:cursor IS NULL OR u.id > :cursor)
AND u.nickname LIKE %:query%
ORDER BY u.id ASC
""")
Slice<User> searchAccountNotInFollow(@Param("query") String query,
@Param("cursor") Long cursor, Pageable pageable, @Param("loginUserId") Long userId);

}
Loading