-
Notifications
You must be signed in to change notification settings - Fork 0
지도 범위 내 클러스터형 공개 다이어리 조회 API 구현 (줌레벨 기준 시/도, 시군구 클러스터) #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Claude의 전체 변경사항 및 관련 파일에 대한 리뷰: 개선된 사항:
주요 이슈:
관련 파일에 대한 영향 분석:
전반적인 의견: |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



📌 PR 제목
지도 내 다이어리 클러스터 조회 API 구현 (줌레벨 기준 시/도, 시군구 클러스터)
✨ 변경 사항
1. MySQL & PostgreSQL 하이버네이트 분리 설정 추가
왜 Config를 분리해야 했는가?
Spring에서 기본적으로 하나의 DataSource, EntityManagerFactory, TransactionManager를 사용하는 단일 DB 환경을 전제로 구성
하지만 이 프로젝트처럼 두 개의 서로 다른 RDBMS (MySQL + PostgreSQL) 을 사용할 경우, 다음과 같은 문제들이 발생
SQL Dialect 충돌
MySQL은 MySQL8Dialect, PostgreSQL은 PostgreSQLDialect를 사용해야 하는데, 단일 설정으로 실행하면 하이버네이트가 한 쪽에만 맞춰져, 다른 쪽 쿼리는 오류 발생
Entity 스캔 범위 충돌
Spring JPA는 @EntityScan, @EnableJpaRepositories 설정에서 지정된 패키지의 엔티티와 레포지토리를 모두 하나의 EntityManager로 등록하려 한다.
PostgreSQL용 Entity를 MySQL의 EntityManager에 등록하려 하면 매핑 오류 혹은 쿼리 실행 오류 발생
따라서 각 DB에 알맞게 등록되기 위해 Config 통해 분리
행정구역 데이터는 PostgreSQL에 MULTIPOLYGON 형태로 저장되어있음
2. 지도 내 다이어리 클러스터 조회 API 구현
사용자가 보고 있는 지도 범위 내에 존재하는 다이어리 개수를 줌 레벨에 따라 클러스터링된 형태로 반환
zoom ≤ 10: 시/도 단위 클러스터링zoom ≥ 11: 시/군/구 단위 클러스터링zoom ≥ 14: 클러스터링 OFF, 개별 다이어리 반환 예정 (후속 예정)areaName,areaId,lat,lon,diaryCount형식으로 클러스터 정보 반환3. PostGIS 기반 PostgreSQL을 Docker로 실행하도록 구성
init.sql을 통해 수동 세팅서버 실행 전 해당 DB가 들어있는 Docker를 Compose 해야 서버 실행 시 에러가 나지 않습니다.
🧑💻 팀원 실행 가이드
docker/init.sql파일은 수동으로 받아서 넣어야 합니다🚀 배포 가이드
init.sql 파일 EC2에 복사
docker-compose up -d 실행 후 서버 구동
docker-compose up -d만 실행 (volume 삭제 금지 ❌)
🔍 기능 구현하면서 고민했던 사항
1. 비즈니스 로직 흐름
기존에는 다음과 같은 방식으로 다이어리 클러스터를 계산
→ 이에 대한 해결 방안으로, 다음과 같은 방식으로 리팩터링:
2. 공간 데이터 다루기 위한 DB선택
PostgreSQL 사용 이유
지도에서 행정구역(시/도, 시/군/구) 단위로 공간 데이터를 다뤄야했다. 예를 들어, 사용자가 지도에서 특정 범위를 보고 있을 때, 그 사각형 범위 안에 있는 시/군/구 혹은 해당 지역 안에 속한 다이어리의 개수를 클러스터링 형태로 제공해야 했다.
단순
위도/경도 between조건으로는 한계가 있었고, 아래와 같은 공간 연산이 필요했었다:ST_IntersectsST_ContainsMySQL도 공간 데이터 다룰 수 있지만, 아래와 같은 단점들이 존재했다.
공간 연산 기능의 한계
ST_Contains,ST_Within등의 함수가 존재하긴 하나, 복잡한 도형 구조(예:MULTIPOLYGON,GEOMETRYCOLLECTION)를 다루는 데 있어 불안정하거나 오류가 자주 발생SHP / GeoJSON 등 외부 공간 데이터 Import의 어려움
shp2pgsql툴을 통해 바로 import 가능PostgreSQL + PostGIS 도입 이후 가능해진 것
예시 쿼리 – 지도 사각형 범위 안에 포함된 시군구 검색:
✅ 체크리스트
📸 스크린샷 (선택)
📌 참고 사항
📌 리뷰 요구 사항