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
8 changes: 5 additions & 3 deletions src/main/java/com/fitlink/service/FacilityRouteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
public interface FacilityRouteService {

RouteResponseDTO getRoute(
float originLat, float originLng,
float destLat, float destLng,
float originLat,
float originLng,
float destLat,
float destLng,
String type
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ public class FacilityRouteServiceImpl implements FacilityRouteService {

@Override
public RouteResponseDTO getRoute(
float originLat, float originLng,
float destLat, float destLng,
float originLat,
float originLng,
float destLat,
float destLng,
String type
) {

return switch (type) {
case "walk" -> tmapRouteService.getPedestrianRoute(originLat, originLng, destLat, destLng);
case "car" -> tmapRouteService.getCarRoute(originLat, originLng, destLat, destLng);
Expand Down
52 changes: 25 additions & 27 deletions src/main/java/com/fitlink/service/TmapRouteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public RouteResponseDTO getTransitRoute(float oLat, float oLng, float dLat, floa
}

/* ---------------------------
* POST 호출 공통
* POST 공통
* --------------------------- */
private TmapRouteDTO post(String url, String body) {

Expand All @@ -121,13 +121,12 @@ private TmapRouteDTO post(String url, String body) {

} catch (Exception e) {
System.err.println("DTO 변환 오류: " + e.getMessage());
e.printStackTrace();
return null;
}
}

/* ---------------------------
* Walk / Car 공통 변환
* Walk / Car 변환
* --------------------------- */
private RouteResponseDTO convertWalkCar(String type, TmapRouteDTO dto) {

Expand All @@ -137,6 +136,7 @@ private RouteResponseDTO convertWalkCar(String type, TmapRouteDTO dto) {
.distance(0)
.duration(0)
.path(new ArrayList<>())
.waypoints(new ArrayList<>())
.build();
}

Expand All @@ -145,9 +145,12 @@ private RouteResponseDTO convertWalkCar(String type, TmapRouteDTO dto) {
int minutes = seconds / 60;

List<List<Double>> path = new ArrayList<>();
List<RouteResponseDTO.Waypoint> waypoints = new ArrayList<>();

dto.getFeatures().forEach(feature -> {

var geo = feature.getGeometry();
var prop = feature.getProperties();

if (geo == null || geo.getType() == null) return;

Expand All @@ -161,17 +164,32 @@ private RouteResponseDTO convertWalkCar(String type, TmapRouteDTO dto) {

case "Point" -> {
if (geo.getPoint() != null) {

var c = geo.getPoint();
path.add(List.of(c.get(1), c.get(0)));
double lat = c.get(1);
double lng = c.get(0);

path.add(List.of(lat, lng));

// ★ turnType이 있으면 경유지로 추가
if (prop != null && prop.getTurnType() != null) {

waypoints.add(
new RouteResponseDTO.Waypoint(
lat,
lng,
prop.getDescription()
)
);
}
}
}

case "MultiLineString" -> {
if (geo.getMulti() != null)
geo.getMulti().forEach(line ->
line.forEach(coord ->
path.add(List.of(coord.get(1), coord.get(0)))
));
path.add(List.of(coord.get(1), coord.get(0)))));
}
}
});
Expand All @@ -181,6 +199,7 @@ private RouteResponseDTO convertWalkCar(String type, TmapRouteDTO dto) {
.distance(distance)
.duration(minutes)
.path(path)
.waypoints(waypoints)
.build();
}

Expand All @@ -194,30 +213,9 @@ private RouteResponseDTO convertTransit(TransitRouteDTO dto) {

int totalDuration = it.getDuration() / 60;

List<RouteResponseDTO.RouteStep> steps = new ArrayList<>();

for (TransitRouteDTO.Leg leg : it.getLegs()) {

String instruction = switch (leg.getMode()) {
case "WALK" -> "도보 이동";
case "BUS" -> leg.getRoute() + " 버스 이동";
case "SUBWAY" -> leg.getRoute() + " 지하철 이동";
default -> "이동";
};

steps.add(
new RouteResponseDTO.RouteStep(
leg.getMode().toLowerCase(),
instruction,
leg.getSectionTime() / 60
)
);
}

return RouteResponseDTO.builder()
.type("transit")
.duration(totalDuration)
.routes(steps)
.build();
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/fitlink/web/dto/RouteRequestDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter @Setter
public class RouteRequestDTO {
private float originLat;
private float originLng;
private float destLat;
private float destLng;
private String type; // walk, car, transit

// 경유지 (위도/경도 리스트)
private List<Waypoint> waypoints;

@Getter @Setter
public static class Waypoint {
private float lat;
private float lng;
}

}
19 changes: 10 additions & 9 deletions src/main/java/com/fitlink/web/dto/RouteResponseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
@Builder
public class RouteResponseDTO {

private String type;
private int duration;
private int distance; // 도보/자동차만
private List<List<Double>> path; // 도보/자동차만
private List<RouteStep> routes; // 대중교통만
private String type; // walk / car / transit
private int duration; // minutes
private int distance; // meters (walk/car only)
private List<List<Double>> path;

private List<Waypoint> waypoints; // ★ 자동 추출된 안내 포인트

@Data
@AllArgsConstructor
public static class RouteStep {
private String mode;
private String instruction;
private int duration;
public static class Waypoint {
private double lat;
private double lng;
private String description; // 예: "좌회전", "횡단보도 건너기"
}
}
16 changes: 4 additions & 12 deletions src/main/java/com/fitlink/web/dto/TmapRouteDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.util.List;

@Data
Expand All @@ -20,38 +21,29 @@ public static class Feature {

@Data
public static class Geometry {

private String type;

// Point -> [lng, lat]
private List<Double> point;

// LineString -> [[lng, lat], [lng, lat] ...]
private List<List<Double>> line;

// MultiLineString -> [[[lng, lat], ...], [...]]
private List<List<List<Double>>> multi;
private List<Double> point; // [lng, lat]
private List<List<Double>> line; // [[lng,lat], ...]
private List<List<List<Double>>> multi; // [[[lng,lat]...]]

@JsonAnySetter
public void handle(String key, Object value) {
if (!"coordinates".equals(key)) return;

if (value instanceof List<?> list) {

// 1) Point : [lng, lat]
if (!list.isEmpty() && list.get(0) instanceof Number) {
this.point = (List<Double>) value;
return;
}

// 2) LineString : [[lng,lat], [lng,lat]]
if (!list.isEmpty() && list.get(0) instanceof List<?> sub
&& sub.size() == 2 && sub.get(0) instanceof Number) {
this.line = (List<List<Double>>) value;
return;
}

// 3) MultiLineString : [[[lng,lat],...], ...]
if (!list.isEmpty() && list.get(0) instanceof List<?> sub2
&& sub2.get(0) instanceof List<?>) {
this.multi = (List<List<List<Double>>>) value;
Expand Down