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
87 changes: 40 additions & 47 deletions src/main/java/goorm/ddok/map/service/MapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,24 +413,20 @@ public PageResponse<AllMapItemSearchResponse> search(
int page, int size,
String filterCsv
) {
// 1) 검증
validateBounds(swLat, swLng, neLat, neLng);

// 2) 파싱
Set<String> categories = parseCategories(categoryCsv);
// 기본: project,study,player
Set<String> categories = parseCategories(categoryCsv); // 기본 project,study,player,cafe
Set<goorm.ddok.project.domain.TeamStatus> projectStatusFilter = parseProjectTeamStatusFilter(filterCsv);
Set<goorm.ddok.study.domain.TeamStatus> studyStatusFilter = parseStudyTeamStatusFilter(filterCsv);
Set<goorm.ddok.study.domain.TeamStatus> studyStatusFilter = parseStudyTeamStatusFilter(filterCsv);

// 3) 페이지 파라미터+페치상한
page = Math.max(0, page);
size = (size <= 0) ? 20 : size;

final List<AllMapItemSearchResponse> items = new ArrayList<>();

// --- project ---
if (categories.contains("project")) {
var rows = projectRecruitmentRepository.findAllInBounds(swLat, neLat, swLng, neLng);

if (rows != null) {
rows.stream()
.filter(r -> projectStatusFilter.isEmpty() || projectStatusFilter.contains(r.getTeamStatus()))
Expand Down Expand Up @@ -464,7 +460,6 @@ public PageResponse<AllMapItemSearchResponse> search(

if (categories.contains("study")) {
var rows = studyRecruitmentRepository.findAllInBounds(swLat, neLat, swLng, neLng);

if (rows != null) {
rows.stream()
.filter(r -> studyStatusFilter.isEmpty() || studyStatusFilter.contains(r.getTeamStatus()))
Expand Down Expand Up @@ -498,7 +493,6 @@ public PageResponse<AllMapItemSearchResponse> search(

if (categories.contains("player")) {
var rows = userRepository.findPublicPlayersInBounds(swLat, neLat, swLng, neLng);

if (rows != null) {
rows.forEach(r -> {
User user = userRepository.findById(r.getId())
Expand Down Expand Up @@ -556,7 +550,6 @@ public PageResponse<AllMapItemSearchResponse> search(

if (categories.contains("cafe")) {
var rows = cafeRepository.findAllInBounds(swLat, neLat, swLng, neLng);

if (rows != null) {
rows.forEach(r -> items.add(AllMapItemSearchResponse.builder()
.category("cafe")
Expand All @@ -583,35 +576,45 @@ public PageResponse<AllMapItemSearchResponse> search(
.build())
.build()));
}

}

if (centerLat != null && centerLng != null && !items.isEmpty()) {
final String kw = (keyword == null) ? "" : keyword.trim().toLowerCase();
List<AllMapItemSearchResponse> filtered = items.stream()
.filter(it -> {
if (kw.isEmpty()) return true;
String title = it.getTitle() == null ? "" : it.getTitle().toLowerCase();
String nick = it.getNickname() == null ? "" : it.getNickname().toLowerCase();
return title.contains(kw) || nick.contains(kw);
})
.toList();

if (centerLat != null && centerLng != null && !filtered.isEmpty()) {
final double cLat = centerLat.doubleValue();
final double cLng = centerLng.doubleValue();
items.sort(Comparator.comparingDouble(it -> {
var loc = it.getLocation();
if (loc == null || loc.getLatitude() == null || loc.getLongitude() == null) {
return Double.MAX_VALUE;
}
return haversineKm(cLat, cLng, loc.getLatitude().doubleValue(), loc.getLongitude().doubleValue());
}));

filtered = filtered.stream()
.sorted(Comparator.comparingDouble(it -> {
var loc = it.getLocation();
if (loc == null || loc.getLatitude() == null || loc.getLongitude() == null) {
return Double.MAX_VALUE;
}
return haversineKm(
cLat, cLng,
loc.getLatitude().doubleValue(),
loc.getLongitude().doubleValue()
);
}))
.toList();
}

Pageable pageable = PageRequest.of(page, size);
int total = filtered.size();
int fromIndex = Math.min(page * size, total);
int toIndex = Math.min(fromIndex + size, total);
List<AllMapItemSearchResponse> pageItems =
(fromIndex >= toIndex) ? List.of() : filtered.subList(fromIndex, toIndex);

return PageResponse.of(new PageImpl<>(
items.stream()
.filter(it -> keyword == null || keyword.isBlank()
|| (it.getTitle() != null && it.getTitle().toLowerCase().contains(keyword.toLowerCase()))
|| (it.getNickname() != null && it.getNickname().toLowerCase().contains(keyword.toLowerCase()))
)
.skip((long) pageable.getPageNumber() * pageable.getPageSize())
.limit(pageable.getPageSize())
.toList(),
pageable,
items.size()
));
return PageResponse.of(new PageImpl<>(pageItems, pageable, total));
}

private Set<String> parseCategories(String categoryCsv) {
Expand All @@ -625,36 +628,26 @@ private Set<String> parseCategories(String categoryCsv) {
}

private Set<goorm.ddok.project.domain.TeamStatus> parseProjectTeamStatusFilter(String filterCsv) {
if (filterCsv == null || filterCsv.isBlank()) {
return Collections.emptySet();
}
if (filterCsv == null || filterCsv.isBlank()) return Collections.emptySet();
return Arrays.stream(filterCsv.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(s -> {
try {
return goorm.ddok.project.domain.TeamStatus.valueOf(s.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
try { return goorm.ddok.project.domain.TeamStatus.valueOf(s.toUpperCase()); }
catch (IllegalArgumentException e) { return null; }
})
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}

private Set<goorm.ddok.study.domain.TeamStatus> parseStudyTeamStatusFilter(String filterCsv) {
if (filterCsv == null || filterCsv.isBlank()) {
return Collections.emptySet();
}
if (filterCsv == null || filterCsv.isBlank()) return Collections.emptySet();
return Arrays.stream(filterCsv.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(s -> {
try {
return goorm.ddok.study.domain.TeamStatus.valueOf(s.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
try { return goorm.ddok.study.domain.TeamStatus.valueOf(s.toUpperCase()); }
catch (IllegalArgumentException e) { return null; }
})
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public interface TechStackRepository extends JpaRepository<TechStack, Long> {
List<String> findNamesByKeyword(String keyword, Pageable pageable);

List<TechStack> findByNameIn(Collection<String> names);

// 기술 스택 찾기
Optional<TechStack> findFirstByNameIgnoreCaseOrderByIdAsc(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ public interface UserTechStackRepository extends JpaRepository<UserTechStack, Lo

// 다건 + 페이징 조회용
Page<UserTechStack> findByUserId(Long userId, Pageable pageable);

// userTechStack 테이블에 이미 존재하는지 확인
boolean existsByUserIdAndTechStackId(Long userId, Long techStackId);
}
32 changes: 18 additions & 14 deletions src/main/java/goorm/ddok/member/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,22 +370,26 @@ private void saveUserPositions(User user, String mainPosition, List<String> subP
}

private void saveUserTechStacks(User user, List<String> techStacks) {
if (techStacks == null || techStacks.isEmpty()) return;

if (techStacks != null && !techStacks.isEmpty()) {
for (String techStackName : techStacks) {
if (techStackName != null && !techStackName.trim().isEmpty()) {
TechStack techStack = techStackRepository.findByName(techStackName)
.orElseGet(() -> techStackRepository.save(
TechStack.builder()
.name(techStackName.trim())
.build()
));
UserTechStack userTechStack = UserTechStack.builder()
.user(user)
.techStack(techStack)
.build();
userTechStackRepository.save(userTechStack);
}
if (techStackName == null) continue;

String name = techStackName.trim();

if (name.isEmpty()) continue;

TechStack tech = techStackRepository
.findFirstByNameIgnoreCaseOrderByIdAsc(name)
.orElseGet(() -> techStackRepository.save(
TechStack.builder().name(name).build()
));

// 같은 유저-스택 중복 연결 방지
if (!userTechStackRepository.existsByUserIdAndTechStackId(user.getId(), tech.getId())) {
userTechStackRepository.save(
UserTechStack.builder().user(user).techStack(tech).build()
);
}
}
}
Expand Down
Loading