Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,6 +1,5 @@
package goorm.ddok.member.repository;

import goorm.ddok.member.domain.UserLocation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down Expand Up @@ -206,7 +205,7 @@ interface UserOverlayRow {
Optional<UserOverlayRow> findOverlayById(@Param("id") Long id);

@Query("""
SELECT DISTINCT u FROM User u
SELECT u FROM User u
LEFT JOIN FETCH u.location loc
LEFT JOIN u.positions pos
WHERE (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import jakarta.persistence.criteria.*;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand All @@ -25,6 +26,7 @@

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -46,7 +48,22 @@ public Page<ProfileSearchResponse> searchPlayers(String keyword, int page, int s
String searchKeyword = hasText(keyword) ? keyword.trim() : null;

Page<User> rows = userRepository.searchPlayersWithKeyword(searchKeyword, pageable);
return rows.map(u -> toResponse(u, currentUserId));

List<User> distinctUsers = rows.getContent().stream()
.collect(Collectors.toMap(User::getId, user -> user, (existing, replacement) -> existing))
.values()
.stream()
.sorted((u1, u2) -> {
int nicknameCompare = u1.getNickname().compareToIgnoreCase(u2.getNickname());
return nicknameCompare != 0 ? nicknameCompare : u1.getId().compareTo(u2.getId());
})
.toList();

List<ProfileSearchResponse> responses = distinctUsers.stream()
.map(u -> toResponse(u, currentUserId))
.toList();

return new PageImpl<>(responses, pageable, rows.getTotalElements());
}

// 나머지 메서드들은 그대로 유지
Expand Down