Conversation
- Hibernate Spatial, JTS 라이브러리 의존성을 추가하여 공간 데이터 처리 기능을 도입 - Store 엔티티의 위도, 경도 필드를 Point 타입으로 변경하여 공간 인덱스를 활용할 수 있도록 개선
- 기존에 애플리케이션 레벨에서 처리하던 거리 계산 및 위치 필터링 로직을 DB의 공간 쿼리를 사용하도록 변경하여 검색 성능을 최적화 - Native Query를 사용하여 특정 영역 내 가게를 효율적으로 검색 - 변경된 Repository 메소드를 사용하도록 StoreService의 `searchStores` 로직을 리팩토링
Walkthrough런타임 의존성에 공간 기능(JTS, Hibernate Spatial)을 추가하고, Store 엔티티의 위도/경도 필드를 JTS Point로 교체했습니다. 저장소에 네이티브 공간 쿼리와 프로젝션을 도입해 서비스 로직을 DB 단일 호출로 재구성했으며, 거리/좌표 계산은 Point 기반으로 전환되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client as Client
participant StoreService as StoreService
participant StoreRepository as StoreRepository
participant DB as Database (SQL + Spatial)
Client->>StoreService: searchStores(category, menuName, bounds, userLatLng, sort)
StoreService->>StoreRepository: findStoresAndMenusInArea(userLng, userLat, category, menuName, SW/NE)
StoreRepository->>DB: Native SQL (MBRContains + ST_GeomFromText, distance calc)
DB-->>StoreRepository: List<StoreSearchResult>
StoreRepository-->>StoreService: 결과 반환
StoreService->>StoreService: DTO 매핑 및 정렬(가격/거리)
StoreService-->>Client: StoreSearchDto 리스트
Note over StoreRepository,DB: 변경: 공간 인덱스/함수 활용한 단일 쿼리로 필터·최저가 선택·거리 계산 수행
sequenceDiagram
autonumber
participant Client as Client
participant StoreService as StoreService
participant DB as Database
Client->>StoreService: getStoreDetails(storeId, userLatLng)
StoreService->>DB: 조회 Store + 관련 데이터
DB-->>StoreService: Store(entity with Point location)
StoreService->>StoreService: distance = haversine(location.x, location.y, userLng, userLat)
StoreService-->>Client: StoreDetailDto(위도=location.y, 경도=location.x, distance)
Note over StoreService: 변경: 위도/경도 필드 → Point.x/.y 사용
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/kotlin/com/eodigo/domain/restaurant/service/StoreService.kt (1)
90-106: 거리 계산 시 위도/경도 순서가 뒤바뀌었습니다.
Point의x는 경도,y는 위도입니다. 현재calculateDistance호출에서lat2에location.x(경도),lon2에location.y(위도)를 전달하고 있어 계산이 완전히 틀어집니다.lat2 = store.location.y,lon2 = store.location.x로 교체해야 올바른 거리가 나옵니다.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
build.gradle.kts(1 hunks)src/main/kotlin/com/eodigo/domain/restaurant/entity/Store.kt(1 hunks)src/main/kotlin/com/eodigo/domain/restaurant/repository/StoreRepository.kt(1 hunks)src/main/kotlin/com/eodigo/domain/restaurant/service/StoreService.kt(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.kt
⚙️ CodeRabbit configuration file
src/**/*.kt: ## 1. Kotlin 코딩 컨벤션
- Kotlin 공식 코딩 컨벤션을 준수해야 합니다.
- 클래스는 PascalCase, 함수/변수는 camelCase, 상수는 UPPER_SNAKE_CASE로 작성하세요.
- 변경 불가능한 데이터는 val을, 변경이 필요한 경우에만 var를 사용하세요.
- Null Pointer Exception을 유발하는 !! 연산자 사용을 금지합니다.
- 의미를 알 수 없는 숫자나 문자열(매직 넘버) 대신 명명된 상수를 사용하세요.
2. Spring Boot
- Controller-Service-Repository 계층형 아키텍처의 책임을 분리하세요.
- Controller의 요청/응답에는 반드시 DTO를 사용하고, 엔티티를 직접 노출하지 마세요.
- 민감한 설정 정보(DB 계정, API 키 등)는 코드에 하드코딩하지 말고 외부에서 주입하세요.
- @Autowired 필드 주입 대신 생성자 주입을 사용하세요.
3. JPA 및 데이터베이스
- @entity 클래스에 Setter 사용을 지양하고, 비즈니스 메서드를 통해 상태를 변경하세요.
- 데이터를 변경하지 않는 조회용 Service 메서드에는 @transactional(readOnly = true)를 적용하세요.
- N+1 문제가 발생하는 쿼리가 있는지 확인하고, Fetch Join으로 최적화하세요.
- 엔티티의 양방향 연관관계에서 toString()을 사용할 경우 순환 참조가 발생하지 않도록 주의하세요.
4. 예외 처리
- @RestControllerAdvice를 사용하여 예외를 전역에서 일관되게 처리하세요.
- RuntimeException 대신, 의미가 명확한 커스텀 예외(예: MemberNotFoundException)를 정의하여 사용하세요.
Files:
src/main/kotlin/com/eodigo/domain/restaurant/entity/Store.ktsrc/main/kotlin/com/eodigo/domain/restaurant/service/StoreService.ktsrc/main/kotlin/com/eodigo/domain/restaurant/repository/StoreRepository.kt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build-and-test
📝 작업 내용
⚡ 주요 변경사항
📌 리뷰 포인트
📋 체크리스트
feat: 기능1 추가)Summary by CodeRabbit