Skip to content
Merged
13 changes: 13 additions & 0 deletions src/main/java/com/wayble/server/common/config/WebClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import com.wayble.server.common.client.tmap.TMapProperties;
import com.wayble.server.direction.external.kric.KricProperties;
import com.wayble.server.direction.external.opendata.OpenDataProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.DefaultUriBuilderFactory;

@Configuration
@RequiredArgsConstructor
public class WebClientConfig {

private final TMapProperties tMapProperties;
private final KricProperties kricProperties;
private final OpenDataProperties openDataProperties;

@Bean
public WebClient webClient() {
Expand All @@ -38,4 +41,14 @@ public WebClient kricWebClient() {
.filter(throwable -> throwable instanceof org.springframework.web.reactive.function.client.WebClientRequestException)))
.build();
}

@Bean
public WebClient openDataWebClient() {
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(openDataProperties.baseUrl());
factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY);
return WebClient.builder()
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(512 * 1024))
.uriBuilderFactory(factory)
.build();
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/wayble/server/direction/dto/InternalStep.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.wayble.server.direction.dto;

import java.util.List;

import com.wayble.server.direction.dto.response.TransportationResponseDto;
import com.wayble.server.direction.entity.type.DirectionType;

// 대중교통 길찾기에 사용하기 위한 내부용 DTO
public record InternalStep(
DirectionType mode,
List<TransportationResponseDto.MoveInfo> moveInfo,
String routeName,
Integer moveNumber,
TransportationResponseDto.BusInfo busInfo,
TransportationResponseDto.SubwayInfo subwayInfo,
String from,
String to,
Long routeId,
NodeRef startNode,
NodeRef endNode
) {}
8 changes: 8 additions & 0 deletions src/main/java/com/wayble/server/direction/dto/NodeRef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wayble.server.direction.dto;

public record NodeRef(
Long id,
String stationName,
Double latitude,
Double longitude
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ public static Edge createEdge(Long id, Node startNode, Node endNode, DirectionTy
.route(null)
.build();
}

public static Edge createEdgeWithRoute(Long id, Node startNode, Node endNode, DirectionType edgeType, Route route) {
return Edge.builder()
.id(id)
.edgeType(edgeType)
.startNode(startNode)
.endNode(endNode)
.route(route)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.*;

import java.util.List;
import java.util.ArrayList;

@Entity
@Getter
Expand Down Expand Up @@ -39,4 +40,15 @@ public class Route {
// 휠체어 정보
@OneToMany(mappedBy = "route", fetch = FetchType.LAZY)
private List<Wheelchair> wheelchairs;

public static Route createRoute(Long routeId, String routeName, DirectionType routeType, Node startNode, Node endNode) {
return Route.builder()
.routeId(routeId)
.routeName(routeName)
.routeType(routeType)
.startNode(startNode)
.endNode(endNode)
.wheelchairs(new ArrayList<>())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

@ConfigurationProperties(prefix = "opendata.api")
public record OpenDataProperties(
String key,
String baseUrl,
String encodedKey,
Endpoints endpoints,
int timeout,
String userAgent,
String accept
) {
public record Endpoints(String arrivals, String stationByName) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public record Item(
@JsonProperty("busType1") String busType1,
@JsonProperty("busType2") String busType2,
@JsonProperty("term") String term,
@JsonProperty("busRouteId") String busRouteId
@JsonProperty("busRouteId") String busRouteId,
@JsonProperty("rtNm") String rtNm,
@JsonProperty("stNm") String stNm,
@JsonProperty("arsId") String arsId
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public record StationSearchMsgBody(

@JsonIgnoreProperties(ignoreUnknown = true)
public record StationItem(
String arsId,
String stId,
String stNm,
String tmX,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.wayble.server.direction.repository;

import com.wayble.server.direction.entity.type.DirectionType;

public interface EdgeBoundingBoxProjection {
Long getEdgeId();
Long getStartNodeId();
Long getEndNodeId();
DirectionType getEdgeType();
String getStartStationName();
Double getStartLatitude();
Double getStartLongitude();
String getEndStationName();
Double getEndLatitude();
Double getEndLongitude();
Long getRouteId();
String getRouteName();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wayble.server.direction.repository;

import com.wayble.server.direction.entity.transportation.Edge;
import com.wayble.server.direction.repository.EdgeBoundingBoxProjection;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -16,13 +17,27 @@ public interface EdgeRepository extends JpaRepository<Edge, Long> {
"LEFT JOIN FETCH e.route")
List<Edge> findAllWithNodesAndRoute();

@Query("SELECT DISTINCT e FROM Edge e " +
"JOIN FETCH e.startNode s " +
"JOIN FETCH e.endNode en " +
"LEFT JOIN FETCH e.route " +
@Query("SELECT " +
"e.id as edgeId, " +
"s.id as startNodeId, " +
"en.id as endNodeId, " +
"e.edgeType as edgeType, " +
"s.stationName as startStationName, " +
"s.latitude as startLatitude, " +
"s.longitude as startLongitude, " +
"en.stationName as endStationName, " +
"en.latitude as endLatitude, " +
"en.longitude as endLongitude, " +
"r.routeId as routeId, " +
"r.routeName as routeName " +
"FROM Edge e " +
"JOIN e.startNode s " +
"JOIN e.endNode en " +
"LEFT JOIN e.route r " +
"WHERE (s.latitude BETWEEN :minLat AND :maxLat AND s.longitude BETWEEN :minLon AND :maxLon) OR " +
"(en.latitude BETWEEN :minLat AND :maxLat AND en.longitude BETWEEN :minLon AND :maxLon)")
List<Edge> findEdgesInBoundingBox(
"(en.latitude BETWEEN :minLat AND :maxLat AND en.longitude BETWEEN :minLon AND :maxLon) " +
"ORDER BY e.id")
List<EdgeBoundingBoxProjection> findEdgesInBoundingBox(
@Param("minLat") double minLat,
@Param("maxLat") double maxLat,
@Param("minLon") double minLon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@
import org.springframework.data.repository.query.Param;

public interface FacilityRepository extends JpaRepository<Facility, Long> {
@Query("SELECT f FROM Facility f " +
"LEFT JOIN FETCH f.lifts " +
"WHERE f.id = :nodeId")
Optional<Facility> findByNodeId(@Param("nodeId") Long nodeId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.wayble.server.direction.repository;

import com.wayble.server.direction.entity.type.DirectionType;

public interface NodeBoundingBoxProjection {
Long getId();
String getStationName();
DirectionType getNodeType();
Double getLatitude();
Double getLongitude();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wayble.server.direction.repository;

import com.wayble.server.direction.entity.transportation.Node;
import com.wayble.server.direction.repository.NodeBoundingBoxProjection;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -9,10 +10,17 @@

public interface NodeRepository extends JpaRepository<Node, Long> {

@Query("SELECT n FROM Node n WHERE " +
@Query("SELECT " +
"n.id as id, " +
"n.stationName as stationName, " +
"n.nodeType as nodeType, " +
"n.latitude as latitude, " +
"n.longitude as longitude " +
"FROM Node n WHERE " +
"n.latitude BETWEEN :minLat AND :maxLat AND " +
"n.longitude BETWEEN :minLon AND :maxLon")
List<Node> findNodesInBoundingBox(
"n.longitude BETWEEN :minLon AND :maxLon " +
"ORDER BY n.latitude, n.longitude")
List<NodeBoundingBoxProjection> findNodesInBoundingBox(
@Param("minLat") double minLat,
@Param("maxLat") double maxLat,
@Param("minLon") double minLon,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.wayble.server.direction.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.wayble.server.direction.entity.transportation.Route;
import java.util.Optional;

public interface RouteRepository extends JpaRepository<Route, Long>{

@Query("SELECT r.routeName FROM Route r WHERE r.routeId = :routeId")
Optional<String> findRouteNameById(@Param("routeId") Long routeId);
Comment on lines +12 to +13
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

메서드 명칭을 더 구체적으로: byId → byRouteId

JPA 기본 메서드(findById)와 의미가 혼동될 수 있어, byRouteId로의 리네이밍을 제안합니다. 기능 변화는 없습니다.

적용 diff:

-    @Query("SELECT r.routeName FROM Route r WHERE r.routeId = :routeId")
-    Optional<String> findRouteNameById(@Param("routeId") Long routeId);
+    @Query("SELECT r.routeName FROM Route r WHERE r.routeId = :routeId")
+    Optional<String> findRouteNameByRouteId(@Param("routeId") Long routeId);

호출부 업데이트 필요 여부를 아래로 확인해 주세요:


🏁 Script executed:

#!/bin/bash
# 메서드 사용처 확인
rg -n '\bfindRouteNameById\b' -C2

Length of output: 1679


메서드명 변경 시 호출부도 함께 갱신 필요

리팩토링한 메서드명(findRouteNameByRouteId)을 실제 호출부에서도 반영해야 합니다. 아래 위치에서 findRouteNameById를 모두 findRouteNameByRouteId로 변경해 주세요.

  • src/main/java/com/wayble/server/direction/service/BusInfoService.java:36
  • src/main/java/com/wayble/server/direction/service/BusInfoService.java:150

적용 예시:

--- a/src/main/java/com/wayble/server/direction/repository/RouteRepository.java
@@ -11,7 +11,7 @@
     @Query("SELECT r.routeName FROM Route r WHERE r.routeId = :routeId")
-    Optional<String> findRouteNameById(@Param("routeId") Long routeId);
+    Optional<String> findRouteNameByRouteId(@Param("routeId") Long routeId);
--- a/src/main/java/com/wayble/server/direction/service/BusInfoService.java
@@ -33,7 +33,7 @@
     if (busId != null) {
-        var routeName = routeRepository.findRouteNameById(busId);
+        var routeName = routeRepository.findRouteNameByRouteId(busId);
         isShuttleBus = routeName.isPresent() && routeName.get().contains("마포");
     }
@@ -148,7 +148,7 @@
     // busId로 route 정보 조회
-    var routeName = routeRepository.findRouteNameById(busId);
+    var routeName = routeRepository.findRouteNameByRouteId(busId);
     String projectRouteName = routeName.orElse(null);

이렇게 변경하면 JPA 기본 메서드와의 혼동을 피하고, 메서드 의도가 더 명확해집니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Query("SELECT r.routeName FROM Route r WHERE r.routeId = :routeId")
Optional<String> findRouteNameById(@Param("routeId") Long routeId);
@Query("SELECT r.routeName FROM Route r WHERE r.routeId = :routeId")
Optional<String> findRouteNameByRouteId(@Param("routeId") Long routeId);
🤖 Prompt for AI Agents
In src/main/java/com/wayble/server/direction/repository/RouteRepository.java
around lines 12-13 the repository method was renamed to findRouteNameByRouteId;
update all call sites to match: in
src/main/java/com/wayble/server/direction/service/BusInfoService.java at lines
36 and 150 replace calls to findRouteNameById(...) with
findRouteNameByRouteId(...), preserving the same parameters and handling of the
Optional return; ensure imports and compilation pass after the rename.

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ public interface WheelchairInfoRepository extends JpaRepository<Wheelchair, Long

@Query("SELECT w FROM Wheelchair w WHERE w.route.routeId = :routeId")
List<Wheelchair> findByRouteId(@Param("routeId") Long routeId);

@Query("SELECT w.wheelchairLocation FROM Wheelchair w WHERE w.route.routeId = :routeId")
List<String> findWheelchairLocationsByRouteId(@Param("routeId") Long routeId);
}
Loading