Skip to content

Conversation

@hyoinYang
Copy link
Contributor

@hyoinYang hyoinYang commented Aug 6, 2025

✔️ 연관 이슈

📝 작업 내용

  • 자잘한 오타들, 테스트용 코드 수정
  • RestTemplate에서 WebConfig로 수정
  • 직선거리 30km 이상일 때 바로 결과 반환

스크린샷 (선택)

Summary by CodeRabbit

  • 신규 기능

    • 외부 KRIC API 연동을 위한 설정 및 WebClient 지원이 추가되었습니다.
    • 시설(Facility) 정보를 nodeId로 조회할 수 있습니다.
  • 버그 수정

    • 위경도 필드명 오타(Longtitude → Longitude) 수정.
    • 역 이름이 null일 때의 예외 처리 및 경로 병합 시 안정성 개선.
  • 기능 개선

    • 교통 경로 요청 방식이 GET에서 POST로 변경되었습니다.
    • 30km 초과 경로 요청 시 오류 메시지가 제공됩니다.
    • 경로 탐색 알고리즘(Dijkstra) 내부 상수 및 로깅 개선.
    • 외부 API 호출 방식이 RestTemplate에서 WebClient로 변경되어 성능 및 비동기 지원이 향상되었습니다.
  • 보안

    • /api/v1/directions/** 경로에 대한 인증 없이 접근이 더 이상 허용되지 않습니다.
  • 리팩터링

    • 코드 구조 개선 및 불필요한 서비스 클래스, 설정 파일 제거.
    • 패키지 구조 정리 및 DTO 위치 변경.

@hyoinYang hyoinYang self-assigned this Aug 6, 2025
@hyoinYang hyoinYang added the 🛠️ fix 기능 오류 및 코드 개선이 필요한 곳 수정 label Aug 6, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

이 변경사항은 Kric 외부 서비스 지원 추가, WebClient 기반 HTTP 호출로의 전환, 엔티티 및 DTO 필드명 개선, 보안 및 엔드포인트 메서드 변경, Builder/Factory 패턴 도입, 각종 상수화 및 로깅 강화, 그리고 일부 패키지 구조 정비를 포함합니다.

Changes

Cohort / File(s) Change Summary
Kric 외부 서비스 지원 및 설정
src/main/java/com/wayble/server/ServerApplication.java, src/main/java/com/wayble/server/common/config/WebClientConfig.java, src/main/java/com/wayble/server/direction/external/kric/KricProperties.java
KricProperties 설정 클래스 및 WebClient 빈 추가, 애플리케이션에서 Kric 설정 활성화
RestTemplate → WebClient 전환 및 서비스 리팩토링
src/main/java/com/wayble/server/common/config/RestTemplateConfig.java, src/main/java/com/wayble/server/direction/service/FacilityService.java
RestTemplateConfig 삭제, FacilityService에서 WebClient 사용 및 KricProperties 주입, 로깅 추가, repository 쿼리 변경, 패키지 경로 수정
엔티티/DTO 필드명 및 생성자 개선
src/main/java/com/wayble/server/direction/dto/TransportationResponseDto.java, src/main/java/com/wayble/server/direction/entity/transportation/Edge.java, src/main/java/com/wayble/server/direction/entity/transportation/Node.java
DTO 필드명 오타 수정(Longtitude→Longitude), @nullable 명시, Node 생성자에 DirectionType 추가, Edge 빌더 접근제한 및 정적 팩토리 메서드 도입
패키지 구조 정비
src/main/java/com/wayble/server/direction/external/kric/dto/KricToiletRawBody.java, src/main/java/com/wayble/server/direction/external/kric/dto/KricToiletRawItem.java, src/main/java/com/wayble/server/direction/external/kric/dto/KricToiletRawResponse.java
Kric 관련 DTO 클래스들의 패키지 경로를 외부 서비스 전용으로 이동
보안 및 엔드포인트 변경
src/main/java/com/wayble/server/common/config/SecurityConfig.java, src/main/java/com/wayble/server/direction/controller/TransportationController.java
directions 엔드포인트에 대한 인증 필요로 변경, GET→POST 및 메서드명 변경(getDirections→findDirections)
Repository 기능 확장
src/main/java/com/wayble/server/direction/repository/FacilityRepository.java
nodeId로 Facility 조회하는 메서드 추가
Dijkstra/경로탐색 서비스 개선
src/main/java/com/wayble/server/direction/service/TransportationService.java
거리 제한(30km 초과시 예외) 추가, 상수화, 로깅, 메서드명 오타 수정, EdgeService 의존성 제거 및 정적 팩토리 사용, null 체크 등 로직 개선
에러케이스 추가
src/main/java/com/wayble/server/direction/exception/DirectionErrorCase.java
30km 초과시 에러케이스(DISTANCE_TOO_FAR) 추가
서비스 클래스 제거
src/main/java/com/wayble/server/direction/service/EdgeService.java
EdgeService 클래스 및 createEdge 메서드 삭제

Sequence Diagram(s)

sequenceDiagram
    participant Controller as TransportationController
    participant Service as TransportationService
    participant Repo as FacilityRepository
    participant WebClient as Kric WebClient

    Controller->>Service: findDirections(request)
    Service->>Service: 거리 30km 초과 여부 체크
    alt 거리 초과
        Service-->>Controller: DISTANCE_TOO_FAR 에러 반환
    else 정상
        Service->>Repo: Facility 정보 조회 (findByNodeId)
        Service->>WebClient: 화장실 정보 등 외부 API 호출
        WebClient-->>Service: 응답 반환
        Service-->>Controller: CommonResponse<TransportationResponseDto> 반환
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

🔧 refactor

Suggested reviewers

  • zyovn

Poem

토끼가 깡총, 코드를 뛰어넘네
Kric도 추가, WebClient로 변신해
30km 넘으면 에러로 깡총!
필드명도 바르고, 로그도 콸콸
패키지 이사, 서비스는 정리
오늘도 코드밭엔 초록빛이 반짝
🥕✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bef0fef and 71aa22c.

📒 Files selected for processing (3)
  • src/main/java/com/wayble/server/ServerApplication.java (2 hunks)
  • src/main/java/com/wayble/server/common/config/WebClientConfig.java (3 hunks)
  • src/main/java/com/wayble/server/direction/exception/DirectionErrorCase.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/java/com/wayble/server/direction/exception/DirectionErrorCase.java
  • src/main/java/com/wayble/server/common/config/WebClientConfig.java
  • src/main/java/com/wayble/server/ServerApplication.java
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/hyoin

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/main/java/com/wayble/server/direction/external/kric/KricProperties.java (1)

1-10: KRIC 설정 클래스 구현이 깔끔하나 validation 추가 고려해보세요.

Java record를 사용한 불변 설정 클래스 구현이 좋습니다. 다만 API 키와 Base URL이 필수값인 경우 validation 어노테이션을 추가하는 것을 권장합니다.

다음과 같이 validation을 추가할 수 있습니다:

+import jakarta.validation.constraints.NotBlank;
+
 @ConfigurationProperties(prefix = "kric.api")
 public record KricProperties(
+        @NotBlank(message = "KRIC API key는 필수입니다")
         String key,
+        @NotBlank(message = "KRIC Base URL은 필수입니다")  
         String baseUrl
 ) {
 }
src/main/java/com/wayble/server/direction/external/kric/dto/KricToiletRawItem.java (2)

3-3: 불필요한 import 제거가 필요합니다.

record 클래스에서는 lombok.Getter import가 불필요합니다.

-import lombok.Getter;

5-8: 필드명 의미를 명확히 하는 문서화를 추가해보세요.

stinCd, toltNum과 같은 약어 필드명의 의미를 명확히 하기 위해 JavaDoc이나 주석을 추가하는 것을 권장합니다.

+/**
+ * KRIC 화장실 정보 원시 데이터 아이템
+ * @param stinCd 역코드 (Station Code)
+ * @param toltNum 화장실 번호 (Toilet Number)
+ */
 public record KricToiletRawItem(
         String stinCd,
         String toltNum
 ) {}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19801dd and 3581c05.

📒 Files selected for processing (17)
  • src/main/java/com/wayble/server/ServerApplication.java (2 hunks)
  • src/main/java/com/wayble/server/common/config/RestTemplateConfig.java (0 hunks)
  • src/main/java/com/wayble/server/common/config/SecurityConfig.java (0 hunks)
  • src/main/java/com/wayble/server/common/config/WebClientConfig.java (3 hunks)
  • src/main/java/com/wayble/server/direction/controller/TransportationController.java (2 hunks)
  • src/main/java/com/wayble/server/direction/dto/TransportationResponseDto.java (3 hunks)
  • src/main/java/com/wayble/server/direction/entity/transportation/Edge.java (2 hunks)
  • src/main/java/com/wayble/server/direction/entity/transportation/Node.java (1 hunks)
  • src/main/java/com/wayble/server/direction/exception/DirectionErrorCase.java (1 hunks)
  • src/main/java/com/wayble/server/direction/external/kric/KricProperties.java (1 hunks)
  • src/main/java/com/wayble/server/direction/external/kric/dto/KricToiletRawBody.java (1 hunks)
  • src/main/java/com/wayble/server/direction/external/kric/dto/KricToiletRawItem.java (1 hunks)
  • src/main/java/com/wayble/server/direction/external/kric/dto/KricToiletRawResponse.java (1 hunks)
  • src/main/java/com/wayble/server/direction/repository/FacilityRepository.java (1 hunks)
  • src/main/java/com/wayble/server/direction/service/EdgeService.java (0 hunks)
  • src/main/java/com/wayble/server/direction/service/FacilityService.java (3 hunks)
  • src/main/java/com/wayble/server/direction/service/TransportationService.java (9 hunks)
💤 Files with no reviewable changes (3)
  • src/main/java/com/wayble/server/common/config/SecurityConfig.java
  • src/main/java/com/wayble/server/common/config/RestTemplateConfig.java
  • src/main/java/com/wayble/server/direction/service/EdgeService.java
🔇 Additional comments (20)
src/main/java/com/wayble/server/direction/repository/FacilityRepository.java (1)

11-11: Facility 엔티티에 nodeId 필드 및 인덱스 정의 여부 확인 필요

Facility.java에서 nodeId 필드와 해당 컬럼에 대한 인덱스(@Index, @table(indexes))가 검색되지 않습니다. 수동으로 엔티티 정의를 검토하여 다음 사항을 확인해주세요:

  • src/main/java/com/wayble/server/direction/entity/transportation/Facility.java
    private Long nodeId; (혹은 이에 상응하는 필드) 선언 여부
    • 클래스 레벨 @Table(indexes = @Index(columnList = "node_id")) 또는 필드 레벨 @Index/@Column 어노테이션 적용 여부

위 두 가지가 모두 누락되었다면, findByNodeId(Long nodeId) 메소드가 정상 동작하지 않거나 성능 저하가 발생할 수 있으니 적절히 추가 및 설정해주세요.

src/main/java/com/wayble/server/direction/external/kric/dto/KricToiletRawBody.java (1)

5-7: KRIC API 응답 필드명(item) 확인 필요

현재 KricToiletRawBodyList<KricToiletRawItem> item 하나만을 갖는 깔끔한 record DTO입니다. 다만 컬렉션을 담고 있으므로 복수형 필드명(items)이 더 자연스러울 수 있습니다. 외부 API 스펙에 따라 단수형 item 키를 그대로 써야 한다면 현재 상태가 맞습니다.

– 공식 문서(공공데이터 포털 또는 KRIC 제공 개발자 사이트)에서 응답 JSON 필드명이 item인지, 아니면 items인지 검증
– 만약 items로 응답한다면 DTO 필드명과 JSON 매핑 설정(예: @JsonProperty)을 복수형으로 변경

위 확인 후 API 스펙에 맞춰 필드명을 조정해 주세요.

src/main/java/com/wayble/server/direction/external/kric/dto/KricToiletRawResponse.java (1)

1-7: 패키지 구조 개선과 깔끔한 DTO 구현입니다.

외부 API별로 패키지를 분리한 구조 개선이 좋고, record를 사용한 불변 DTO 구현이 적절합니다.

src/main/java/com/wayble/server/direction/exception/DirectionErrorCase.java (1)

12-12: 새로운 오류 케이스 추가 승인

30km 거리 제한 로직에 대한 오류 케이스 추가가 적절합니다. HTTP 상태 코드와 오류 코드가 기존 패턴을 잘 따르고 있습니다.

src/main/java/com/wayble/server/ServerApplication.java (1)

4-4: 외부 API 설정 속성 추가 승인

Kric API 통합을 위한 설정 속성 추가가 적절합니다. 기존 TMapProperties와 일관된 방식으로 구성되었습니다.

Also applies to: 20-20

src/main/java/com/wayble/server/common/config/WebClientConfig.java (1)

4-4: Kric WebClient 설정 추가 승인

기존 TMap WebClient 설정과 일관된 패턴으로 Kric WebClient 설정이 추가되었습니다. RestTemplate에서 WebClient로의 마이그레이션 작업이 잘 반영되었습니다.

Also applies to: 15-15, 30-35

src/main/java/com/wayble/server/direction/entity/transportation/Node.java (1)

52-58: Node 생성자 업데이트 승인

DirectionType nodeType 매개변수 추가로 노드 생성 시 타입 정보를 명시적으로 지정할 수 있게 되었습니다. 매개변수 순서와 할당 로직이 적절합니다.

src/main/java/com/wayble/server/direction/dto/TransportationResponseDto.java (3)

4-4: Nullable 어노테이션 import 변경 승인

io.micrometer.common.lang.Nullable에서 org.springframework.lang.Nullable로 변경하여 Spring 프레임워크와의 일관성이 향상되었습니다.


16-17: null 허용 필드에 @nullable 어노테이션 추가 승인

routeNameinformation 필드에 @Nullable 어노테이션을 추가하여 null 허용 여부를 명시적으로 표현했습니다. API 문서화와 타입 안전성에 도움이 됩니다.


35-35: 필드명 오타 수정 승인

Longtitude에서 Longitude로 수정하여 올바른 영문 철자를 사용하게 되었습니다.

src/main/java/com/wayble/server/direction/entity/transportation/Edge.java (1)

10-10: 캡슐화 개선을 위한 좋은 리팩토링입니다.

Builder를 private으로 변경하고 static factory method를 제공하여 객체 생성을 제어하는 것은 좋은 설계 패턴입니다. route를 명시적으로 null로 설정하는 것도 도보 경로 생성 시 의도가 명확해집니다.

Also applies to: 38-46

src/main/java/com/wayble/server/direction/controller/TransportationController.java (1)

13-13: HTTP 메서드 변경이 적절합니다.

복잡한 요청 파라미터를 가진 경로 탐색 API의 경우 GET에서 POST로 변경하는 것이 RESTful 설계 관점에서 더 적합합니다. 메서드명도 서비스 레이어와 일치하도록 변경되어 일관성이 향상되었습니다.

Also applies to: 54-55

src/main/java/com/wayble/server/direction/service/FacilityService.java (3)

24-24: WebClient로의 전환과 로깅 추가가 좋습니다.

RestTemplate에서 WebClient로의 전환은 최신 Spring 생태계와 일치하는 좋은 현대화 작업입니다. @Slf4j 추가로 적절한 로깅도 가능해졌습니다.

Also applies to: 28-29


32-32: 리포지토리 메서드 변경이 도메인 모델링을 개선합니다.

findById에서 findByNodeId로 변경하여 비즈니스 의도가 더 명확해졌습니다.


79-92: 외부 API 호출 시 에러 처리가 개선되었습니다.

WebClient 호출을 try-catch로 감싸고 적절한 로깅을 추가한 것이 안정성을 향상시킵니다. 실패 시 빈 Map을 반환하는 것도 적절한 fallback 처리입니다.

src/main/java/com/wayble/server/direction/service/TransportationService.java (5)

32-36: 거리 제한과 상수화가 코드 품질을 향상시킵니다.

30km 거리 제한은 합리적인 비즈니스 규칙이며, 하드코딩된 값들을 상수로 추출한 것은 유지보수성을 크게 개선합니다.

Also applies to: 42-47


21-21: 메서드명 오타 수정과 로깅 개선이 좋습니다.

"Dijstra"를 "Dijkstra"로 수정하고 @Slf4j를 추가하여 코드 품질이 향상되었습니다.

Also applies to: 52-52, 71-71, 128-128, 133-133


100-100: Edge 생성 방식 변경이 캡슐화를 개선합니다.

EdgeService 의존성을 제거하고 Edge.createEdge static factory method를 사용하는 것이 더 깔끔한 설계입니다.

Also applies to: 104-104


260-263: null 안전성 개선이 좋습니다.

스테이션명에 대한 null 체크를 추가하여 NullPointerException을 방지하는 것은 좋은 방어적 프로그래밍입니다.


194-194: 환승·도보 패널티 값 비율 검증 필요

  • METER_CONVERSION = 1000 → haversine 결과(km) × 1000 → m 단위
  • haversine 구현
    • src/main/java/com/wayble/server/direction/service/util/HaversineUtil.java: EARTH_RADIUS 6372.8 km 기준
    • src/main/java/com/wayble/server/direction/service/TransportationService.java: static haversine 메소드 (km 반환)
  • TRANSFER_PENALTY = 2000 (≈ 2 km)
  • STEP_PENALTY = 500 (≈ 0.5 km)

위치를 막론하고 보행 구간 평균 200~400 m, 환승 시 체감 거리/시간 등이 훨씬 짧은 점을 고려하면,
패널티가 너무 커 실제 최적 경로에 영향을 줄 수 있습니다.
따라서 아래 항목을 직접 검증해 주세요.

  • 대표 노선 시나리오(현실적 출발지·도착지)에서
    • 패널티 미적용 vs 적용 시 경로 변화
    • 평균 정류장 간 거리 비교
  • 보행 속도(분당 m)와 환승 소요 시간(분)을 거리 환산해 패널티에 반영

Copy link
Member

@zyovn zyovn left a comment

Choose a reason for hiding this comment

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

수고하셨습니다! 👍👍

@hyoinYang hyoinYang merged commit 7a67a62 into develop Aug 7, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🛠️ fix 기능 오류 및 코드 개선이 필요한 곳 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants