Skip to content
Merged
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
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
) {}
Comment on lines +11 to +21
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

null 허용 필드에 @nullable 명시 필요 (NPE 방지, 가독성 향상)

WALK/환승 등에서 moveInfo, busInfo, subwayInfo, routeId, startNode, endNode가 null로 사용됩니다. 내부 DTO라도 null 가능성을 타입 시그니처로 드러내면 후속 사용처에서 방어 코드가 단순해지고 리팩터 시 안전합니다.

아래와 같이 명시를 제안합니다.

+import org.springframework.lang.Nullable;

 public record InternalStep(
     DirectionType mode,
-    List<TransportationResponseDto.MoveInfo> moveInfo,
-    String routeName,
+    @Nullable List<TransportationResponseDto.MoveInfo> moveInfo,
+    @Nullable String routeName,
     Integer moveNumber,
-    TransportationResponseDto.BusInfo busInfo,
-    TransportationResponseDto.SubwayInfo subwayInfo,
+    @Nullable TransportationResponseDto.BusInfo busInfo,
+    @Nullable TransportationResponseDto.SubwayInfo subwayInfo,
     String from,
     String to,
-    Long routeId,
-    NodeRef startNode,
-    NodeRef endNode
+    @Nullable Long routeId,
+    @Nullable NodeRef startNode,
+    @Nullable NodeRef endNode
 ) {}
📝 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
List<TransportationResponseDto.MoveInfo> moveInfo,
String routeName,
Integer moveNumber,
TransportationResponseDto.BusInfo busInfo,
TransportationResponseDto.SubwayInfo subwayInfo,
String from,
String to,
Long routeId,
NodeRef startNode,
NodeRef endNode
) {}
import org.springframework.lang.Nullable;
public record InternalStep(
DirectionType mode,
- List<TransportationResponseDto.MoveInfo> moveInfo,
@Nullable List<TransportationResponseDto.MoveInfo> moveInfo,
@Nullable String routeName,
Integer moveNumber,
- TransportationResponseDto.BusInfo busInfo,
@Nullable TransportationResponseDto.BusInfo busInfo,
@Nullable TransportationResponseDto.SubwayInfo subwayInfo,
String from,
String to,
- Long routeId,
- NodeRef startNode,
@Nullable Long routeId,
@Nullable NodeRef startNode,
@Nullable NodeRef endNode
) {}
🤖 Prompt for AI Agents
In src/main/java/com/wayble/server/direction/dto/InternalStep.java around lines
11 to 21, annotate nullable fields to make nullability explicit: add a suitable
@Nullable import (e.g., javax.annotation.Nullable or
org.jetbrains.annotations.Nullable) and apply @Nullable to moveInfo, busInfo,
subwayInfo, routeId, startNode, and endNode in the constructor/record signature;
ensure the chosen @Nullable is imported and the rest of the code compiles.

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);
}
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
Loading