Skip to content
Open
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
Expand Up @@ -11,7 +11,10 @@

@Entity
@Getter
@Table(name = "members")
@Table(
name = "members",
indexes = @Index(name = "idx_member_location", columnList = "latitude, longitude")
)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

import java.math.BigDecimal;
import java.util.List;

public interface MemberRepository extends JpaRepository<Member, Long> {
Expand Down Expand Up @@ -37,9 +36,22 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
@Query("""
SELECT m
FROM Member m
WHERE m.latitude IS NOT NULL
WHERE m.latitude IS NOT NULL
AND m.longitude IS NOT NULL
AND m.isOnboarded = true
""")
List<Member> findAllWithLocation();

@Query("""
SELECT m
FROM Member m
WHERE m.latitude BETWEEN :minLat AND :maxLat
AND m.longitude BETWEEN :minLon AND :maxLon
""")
List<Member> findMembersInBoundingBox(
@Param("minLat") BigDecimal minLat,
@Param("maxLat") BigDecimal maxLat,
@Param("minLon") BigDecimal minLon,
@Param("maxLon") BigDecimal maxLon
);
Comment on lines +45 to +56
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

isOnboarded 조건이 빠져 추천 대상이 넓어졌습니다.

이 메서드는 기존 findAllWithLocation() 경로를 대체해서 쓰이는데, 이전 쿼리에 있던 m.isOnboarded = true 가 빠져 아직 온보딩되지 않은 회원도 추천 후보에 포함될 수 있습니다. 기존 동작을 유지하려면 같은 필터를 여기에도 넣어야 합니다.

수정 예시
     `@Query`("""
     SELECT m
     FROM Member m
     WHERE m.latitude BETWEEN :minLat AND :maxLat
     AND m.longitude BETWEEN :minLon AND :maxLon
+    AND m.isOnboarded = true
     """)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@member/src/main/java/kr/co/readingtown/member/repository/MemberRepository.java`
around lines 45 - 56, The JPQL query in
MemberRepository.findMembersInBoundingBox is missing the onboarding filter so
un-onboarded users are included; update the query in the
findMembersInBoundingBox method to include the condition m.isOnboarded = true
(i.e., add "AND m.isOnboarded = true" to the WHERE clause) so it matches the
previous findAllWithLocation behavior and still returns List<Member> without
adding new parameters.

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,32 @@ public List<BookRecommendationResponseDto> recommendBooks(Long memberId) {
public List<LocalMemberRecommendationDto> recommendLocalMembers(Long memberId) {
Member currentMember = memberRepository.findById(memberId)
.orElseThrow(MemberException.NotFoundMember::new);

if (currentMember.getLatitude() == null || currentMember.getLongitude() == null) {
return List.of();
}

List<Member> allMembers = memberRepository.findAllWithLocation();

return allMembers.stream()

// 바운딩 박스 계산 (반경 1km)
final double RADIUS_KM = 1.0;
final double LAT_DEGREE_PER_KM = 1.0 / 110.574;
double currentLat = currentMember.getLatitude().doubleValue();
double currentLon = currentMember.getLongitude().doubleValue();
double latDelta = RADIUS_KM * LAT_DEGREE_PER_KM;
double lonDelta = RADIUS_KM / (111.320 * Math.cos(Math.toRadians(currentLat)));

BigDecimal minLat = BigDecimal.valueOf(currentLat - latDelta);
BigDecimal maxLat = BigDecimal.valueOf(currentLat + latDelta);
BigDecimal minLon = BigDecimal.valueOf(currentLon - lonDelta);
BigDecimal maxLon = BigDecimal.valueOf(currentLon + lonDelta);

List<Member> allMembers = memberRepository.findMembersInBoundingBox(minLat, maxLat, minLon, maxLon);

List<LocalMemberRecommendationDto> result = allMembers.stream()
.filter(member -> !member.getMemberId().equals(memberId))
.filter(member -> member.getLatitude() != null && member.getLongitude() != null)
.map(member -> {
double distance = calculateDistance(
currentMember.getLatitude().doubleValue(),
currentMember.getLongitude().doubleValue(),
currentLat,
currentLon,
member.getLatitude().doubleValue(),
member.getLongitude().doubleValue()
);
Expand All @@ -141,6 +153,8 @@ public List<LocalMemberRecommendationDto> recommendLocalMembers(Long memberId) {
.sorted(Comparator.comparing(LocalMemberRecommendationDto::distanceKm))
.limit(10)
.collect(Collectors.toList());

return result;
}

/**
Expand Down