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
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.back.web7_9_codecrete_be.domain.location.controller;

import com.back.web7_9_codecrete_be.domain.location.dto.KakaoRouteFeResponse;
import com.back.web7_9_codecrete_be.domain.location.dto.KakaoRouteSectionFeResponse;
import com.back.web7_9_codecrete_be.domain.location.dto.response.KakaoLocalResponse;
import com.back.web7_9_codecrete_be.domain.location.dto.response.KakaoMobilityResponse;
import com.back.web7_9_codecrete_be.domain.location.dto.request.KakaoRouteTransitRequest;
import com.back.web7_9_codecrete_be.domain.location.dto.response.KakaoRouteTransitResponse;
import com.back.web7_9_codecrete_be.domain.location.service.KakaoLocalService;
import com.back.web7_9_codecrete_be.global.error.code.LocationErrorCode;
Expand All @@ -16,6 +19,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

@Tag(name = "Location - Kakao", description = "카카오 로컬 API 연동(주변 음식점 조회, 좌표→주소 변환) 관련 엔드포인트")
Expand Down Expand Up @@ -97,6 +101,8 @@ public List<KakaoMobilityResponse.Guide> navigateGuides(
.flatMap(section -> section.getGuides().stream())
.toList();
}


@GetMapping("/navigate/summary")
public KakaoMobilityResponse.Summary navigateSummary(
@RequestParam double startX,
Expand All @@ -119,27 +125,53 @@ public KakaoMobilityResponse.Summary navigateSummary(

}

//카카오 자동차 api인데, 경유지가 존재하는 경우에 사용
@PostMapping("/navigate/onlyguide")
public List<KakaoRouteTransitResponse.Guide> navigateOnlyGuides(
@RequestParam double startX,
@RequestParam double startY,
@RequestParam double endX,
@RequestParam double endY,
@RequestParam double wayX,
@RequestParam double wayY
public KakaoRouteSectionFeResponse navigateOnlyGuides(@RequestBody KakaoRouteTransitRequest req
) {
KakaoRouteTransitResponse res = kakaoLocalService.NaviSearchTransit(startX, startY, endX, endY, wayX, wayY);

if (res == null || res.getRoutes() == null || res.getRoutes().isEmpty()) {
return List.of();
}
KakaoRouteTransitResponse res = kakaoLocalService.NaviSearchTransit(req);
KakaoRouteTransitResponse.Route route = res.getRoutes().get(0);

KakaoRouteTransitResponse.Route route0 = res.getRoutes().get(0);
KakaoRouteTransitResponse.Summary summary = route.getSummary();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

import가 안되는 문제가 있었던걸까요? 아니면 중복된 클래스 명이 있었던 걸까요?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

그냥 route0보다는 route로 하는게 보기 편해서 바꿨습니다,,


return route0.getSections().stream()
.filter(section -> section.getGuides() != null && !section.getGuides().isEmpty())
.flatMap(section -> section.getGuides().stream())
.toList();
List<Object> points = new ArrayList<>(); // 출발지, 경유지, 목적지 좌표를 저장

points.add(summary.getOrigin());
points.addAll(summary.getWaypoints()); // Waypoints는 배열이니까 addAll 사용
points.add(summary.getDestination());


// 구간별 좌표, Distance, Duration 표현
List<KakaoRouteFeResponse> sections = new ArrayList<>();

for (int i = 0; i < route.getSections().size(); i++) {
KakaoRouteTransitResponse.Section section = route.getSections().get(i);

sections.add(new KakaoRouteFeResponse( //sections 리스트에 각각의 section 정보들을 추가
i,
section.getDistance(),
section.getDuration(),
points.get(i), // 출발지
points.get(i + 1) // 목적지
));
}

// distance전체 합계
int totalDistance = route.getSections().stream()
.mapToInt(KakaoRouteTransitResponse.Section::getDistance)
.sum();

// duration 전체 합계
int totalDuration = route.getSections().stream()
.mapToInt(KakaoRouteTransitResponse.Section::getDuration)
.sum();

return new KakaoRouteSectionFeResponse(
totalDistance,
totalDuration,
sections
);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.back.web7_9_codecrete_be.domain.location.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class KakaoRouteFeResponse { //경유지까지의 인덱스, 거리, 시간, 좌표를 나타냄
private int routeIndex;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

응답에는 @Schema 써서 설명을 붙여주면 좋을 것 같습니다!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

넵 스웨거 설정은 방학중에 다 완료해놓겠습니다!

private int distance;
private int duration;
private Object from;
private Object to;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.back.web7_9_codecrete_be.domain.location.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;
@Data
@AllArgsConstructor
public class KakaoRouteSectionFeResponse { //프론트에서 원하는 전체 거리, 시간, 좌표로, section에서는 경유지를 거치는 값들을 저장
private int totalDistance;
private int totalDuration;
private List<KakaoRouteFeResponse> sections;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.back.web7_9_codecrete_be.domain.location.dto.request;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data;

import java.util.List;

@Data
public class KakaoRouteTransitRequest { //Kakao mobility api에서 경유지 추가 response

private Origin origin;
private Destination destination;
private List<Waypoint> waypoints;

private String priority;
private String car_fuel;
private boolean car_hipass;
private boolean alternatives;
private boolean road_details;
private boolean summary;

@Data
public static class Origin {
private double x;
private double y;
private int angle;
}

@Data
public static class Destination {
private double x;
private double y;
}

@Data
public static class Waypoint {
private String name;
private double x;
private double y;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;
@Getter
@AllArgsConstructor
public class KakaoMobilityResponse {
public class KakaoMobilityResponse { //Kakao mobility api에서 전체 response 구조


private List<Route> routes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,98 @@
package com.back.web7_9_codecrete_be.domain.location.dto.response;

import lombok.Getter;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Data;

import java.util.List;

@Getter
@Data
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class KakaoRouteTransitResponse {

private String transId;
private List<Route> routes;

@Getter
@Data
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static class Route {
private int resultCode;
private String resultMsg;
private Summary summary;
private List<Section> sections;
}

@Getter
@Data
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static class Summary {
private Origin origin;
private Destination destination;
private List<Waypoint> waypoints; // ✅ 경유지(요청값)

private List<Waypoint> waypoints;
private String priority;
private Bound bound; // optional일 수 있음
private Fare fare;

private int distance; // meters
private int duration; // seconds
private int distance;
private int duration;
}

@Getter
@Data
public static class Origin {
private String name;
private double x;
private double y;
}

@Getter
@Data
public static class Destination {
private String name;
private double x;
private double y;
}

@Getter
@Data
public static class Waypoint {
private String name;
private double x;
private double y;
}

@Getter
@Data
public static class Bound {
private double minX;
private double minY;
private double maxX;
private double maxY;
}

@Data
public static class Fare {
private int taxi;
private int toll;
}

@Getter
@Data
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static class Section {
private List<Road> roads;
private List<Guide> guides;
private int distance;
private int duration;
private Bound bound; // summary=false일 때만 올 수 있음
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

false일때만 올 수 있다면 해당 클래스를 따로 빼는 것도 괜찮을 것 같습니다.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

넵 알겠습니다!

private List<Road> roads; // summary=false일 때만 올 수 있음
private List<Guide> guides; // summary=false일 때만 올 수 있음
}

@Getter
@Data
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static class Road {
private String name;
private int distance;
private int duration;
private double trafficSpeed;
private int trafficState;
private List<Double> vertexes;
}

@Getter
@Data
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static class Guide {
private String name;
private double x;
Expand All @@ -74,6 +101,6 @@ public static class Guide {
private int duration;
private int type;
private String guidance;
private int road_index;
private int roadIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@

import java.util.List;
@Getter
public class TmapSummaryAllResponse {
public class TmapSummaryAllResponse { // Tmap 대중교통 요약 api response dto

private MetaData metaData;

// ===================== metaData =====================
@Getter
public static class MetaData {
private Plan plan;
private RequestParameters requestParameters;
}

// ===================== plan =====================
@Getter
public static class Plan {
private List<Itinerary> itineraries;
}

// ===================== itineraries =====================
@Getter
public static class Itinerary {

Expand All @@ -35,32 +32,28 @@ public static class Itinerary {
private Fare fare; // 요금 정보
}

// ===================== fare =====================
@Getter
public static class Fare {
private Regular regular;
}

// ===================== regular =====================
@Getter
public static class Regular {
private Currency currency;
private int totalFare; // 대중교통 요금
}

// ===================== currency =====================
@Getter
public static class Currency {
private String symbol; // ₩
private String currency; // 원
private String currencyCode; // KRW
}

// ===================== requestParameters =====================
@Getter
public static class RequestParameters {

private String reqDttm; // 요청 시각 (yyyymmddhhmiss)
private String reqDttm; // 요청 시각

private String startX; // 출발지 경도
private String startY; // 출발지 위도
Expand Down
Loading