Skip to content

Commit 9330819

Browse files
Merge pull request #159 from prgrms-web-devcourse-final-project/feat/#133
[Location] 카카오 모빌리티 api 연동 완료
2 parents c65791f + d2e73fe commit 9330819

17 files changed

Lines changed: 495 additions & 49 deletions

File tree

src/main/java/com/back/web7_9_codecrete_be/domain/location/controller/KakaoApiController.java

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.back.web7_9_codecrete_be.domain.location.controller;
22

3-
import com.back.web7_9_codecrete_be.domain.location.dto.KakaoLocalResponse;
3+
import com.back.web7_9_codecrete_be.domain.location.dto.response.KakaoLocalResponse;
4+
import com.back.web7_9_codecrete_be.domain.location.dto.response.KakaoMobilityResponse;
5+
import com.back.web7_9_codecrete_be.domain.location.dto.response.KakaoRouteTransitResponse;
46
import com.back.web7_9_codecrete_be.domain.location.service.KakaoLocalService;
7+
import com.back.web7_9_codecrete_be.global.error.code.LocationErrorCode;
8+
import com.back.web7_9_codecrete_be.global.error.exception.BusinessException;
59
import com.back.web7_9_codecrete_be.global.rsData.RsData;
610
import io.swagger.v3.oas.annotations.Operation;
711
import io.swagger.v3.oas.annotations.Parameter;
@@ -32,7 +36,7 @@ public class KakaoApiController {
3236
public List<KakaoLocalResponse.Document> KakaoRestaurants(
3337
@RequestParam double lat,
3438
@RequestParam double lon
35-
){
39+
) {
3640
return kakaoLocalService.searchNearbyRestaurants(lat, lon);
3741
}
3842

@@ -46,7 +50,7 @@ public List<KakaoLocalResponse.Document> KakaoRestaurants(
4650
public List<KakaoLocalResponse.Document> KakaoCafes(
4751
@RequestParam double lat,
4852
@RequestParam double lon
49-
){
53+
) {
5054
return kakaoLocalService.searchNearbyCafes(lat, lon);
5155
}
5256

@@ -68,4 +72,74 @@ public RsData<String> coord2Address(
6872
String addressName = kakaoLocalService.coordinateToAddressName(lat, lon);
6973
return RsData.success("좌표를 주소로 변환했습니다.", addressName);
7074
}
75+
76+
77+
@GetMapping("/navigate/guides")
78+
public List<KakaoMobilityResponse.Guide> navigateGuides(
79+
@RequestParam double startX,
80+
@RequestParam double startY,
81+
@RequestParam double endX,
82+
@RequestParam double endY
83+
) {
84+
KakaoMobilityResponse res = kakaoLocalService.NaviSearch(startX, startY, endX, endY);
85+
86+
if (res == null || res.getRoutes() == null || res.getRoutes().isEmpty()) {
87+
return List.of();
88+
}
89+
90+
KakaoMobilityResponse.Route route0 = res.getRoutes().get(0);
91+
if (route0.getSections() == null || route0.getSections().isEmpty()) {
92+
return List.of();
93+
}
94+
95+
return route0.getSections().stream()
96+
.filter(section -> section.getGuides() != null && !section.getGuides().isEmpty())
97+
.flatMap(section -> section.getGuides().stream())
98+
.toList();
99+
}
100+
@GetMapping("/navigate/summary")
101+
public KakaoMobilityResponse.Summary navigateSummary(
102+
@RequestParam double startX,
103+
@RequestParam double startY,
104+
@RequestParam double endX,
105+
@RequestParam double endY
106+
) {
107+
KakaoMobilityResponse res = kakaoLocalService.NaviSearchSummary(startX, startY, endX, endY);
108+
109+
if (res == null || res.getRoutes() == null || res.getRoutes().isEmpty()) {
110+
throw new BusinessException(LocationErrorCode.ROUTE_NOT_FOUND);
111+
}
112+
113+
KakaoMobilityResponse.Route route0 = res.getRoutes().get(0);
114+
if (route0.getSummary() == null) {
115+
throw new BusinessException(LocationErrorCode.ROUTE_NOT_FOUND);
116+
}
117+
118+
return route0.getSummary();
119+
120+
}
121+
122+
@PostMapping("/navigate/onlyguide")
123+
public List<KakaoRouteTransitResponse.Guide> navigateOnlyGuides(
124+
@RequestParam double startX,
125+
@RequestParam double startY,
126+
@RequestParam double endX,
127+
@RequestParam double endY,
128+
@RequestParam double wayX,
129+
@RequestParam double wayY
130+
) {
131+
KakaoRouteTransitResponse res = kakaoLocalService.NaviSearchTransit(startX, startY, endX, endY, wayX, wayY);
132+
133+
if (res == null || res.getRoutes() == null || res.getRoutes().isEmpty()) {
134+
return List.of();
135+
}
136+
137+
KakaoRouteTransitResponse.Route route0 = res.getRoutes().get(0);
138+
139+
return route0.getSections().stream()
140+
.filter(section -> section.getGuides() != null && !section.getGuides().isEmpty())
141+
.flatMap(section -> section.getGuides().stream())
142+
.toList();
143+
}
71144
}
145+

src/main/java/com/back/web7_9_codecrete_be/domain/location/controller/TmapApiController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.back.web7_9_codecrete_be.domain.location.controller;
22

3+
import com.back.web7_9_codecrete_be.domain.location.dto.request.TmapSummaryRequest;
4+
import com.back.web7_9_codecrete_be.domain.location.dto.response.TmapSummaryAllResponse;
5+
import com.back.web7_9_codecrete_be.domain.location.dto.response.TmapSummaryResponse;
36
import com.back.web7_9_codecrete_be.domain.location.service.TmapService;
47
import io.swagger.v3.oas.annotations.Operation;
58
import io.swagger.v3.oas.annotations.Parameter;
@@ -71,4 +74,9 @@ public String getTransit(
7174
) {
7275
return tmapService.getRoute(startX, startY, endX, endY);
7376
}
77+
78+
@GetMapping("/tmap/summary")
79+
public TmapSummaryAllResponse getSummaryTransit(double startX, double startY, double endX, double endY){
80+
return tmapService.getSummaryRoute(startX, startY, endX, endY);
81+
}
7482
}

src/main/java/com/back/web7_9_codecrete_be/domain/location/dto/TmapResponse.java renamed to src/main/java/com/back/web7_9_codecrete_be/domain/location/dto/request/TmapRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
package com.back.web7_9_codecrete_be.domain.location.dto;
1+
package com.back.web7_9_codecrete_be.domain.location.dto.request;
22

33
import io.swagger.v3.oas.annotations.media.Schema;
44
import lombok.Data;
55

66
@Data
7+
78
@Schema(description = "Tmap 대중교통 경로 조회 요청 DTO")
8-
public class TmapResponse {
9+
public class TmapRequest {
910

1011
@Schema(description = "출발지 경도 (longitude)", example = "126.9780")
1112
private String startX;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.back.web7_9_codecrete_be.domain.location.dto.request;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
7+
@Getter
8+
@AllArgsConstructor
9+
public class TmapSummaryRequest {
10+
11+
@Schema(description = "출발지 경도 (longitude)", example = "126.9780")
12+
private double startX;
13+
14+
@Schema(description = "출발지 위도 (latitude)", example = "37.5665")
15+
private double startY;
16+
17+
@Schema(description = "도착지 경도 (longitude)", example = "127.0276")
18+
private double endX;
19+
20+
@Schema(description = "도착지 위도 (latitude)", example = "37.4979")
21+
private double endY;
22+
23+
@Schema(description = "최대 응답 결과 개수", example = "5")
24+
private int count;
25+
26+
@Schema(
27+
description = "응답 포맷 (json / xml)",
28+
example = "json",
29+
allowableValues = {"json", "xml"}
30+
)
31+
private String format;
32+
}

src/main/java/com/back/web7_9_codecrete_be/domain/location/dto/KakaoLocalResponse.java renamed to src/main/java/com/back/web7_9_codecrete_be/domain/location/dto/response/KakaoLocalResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.back.web7_9_codecrete_be.domain.location.dto;
1+
package com.back.web7_9_codecrete_be.domain.location.dto.response;
22

33
import io.swagger.v3.oas.annotations.media.Schema;
44
import lombok.Data;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.back.web7_9_codecrete_be.domain.location.dto.response;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
import java.util.List;
7+
@Getter
8+
@AllArgsConstructor
9+
public class KakaoMobilityResponse {
10+
11+
12+
private List<Route> routes;
13+
14+
@Getter
15+
public static class Route {
16+
private Summary summary;
17+
private List<Section> sections;
18+
}
19+
20+
@Getter
21+
public static class Summary {
22+
private int distance; // meters
23+
private int duration; // seconds
24+
}
25+
26+
@Getter
27+
public static class Section{
28+
private List<Road> roads;
29+
private List<Guide> guides;
30+
public List<Guide> getGuides() {
31+
return guides;
32+
}
33+
}
34+
35+
@Getter
36+
public static class Road{
37+
private List<Double> vertexes;
38+
}
39+
40+
41+
@Getter
42+
public static class Guide {
43+
private String name;
44+
private double x;
45+
private double y;
46+
private int distance;
47+
private int duration;
48+
private int type;
49+
private String guidance;
50+
private int road_index;
51+
}
52+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.back.web7_9_codecrete_be.domain.location.dto.response;
2+
3+
import lombok.Getter;
4+
import java.util.List;
5+
6+
@Getter
7+
public class KakaoRouteTransitResponse {
8+
9+
private List<Route> routes;
10+
11+
@Getter
12+
public static class Route {
13+
private Summary summary;
14+
private List<Section> sections;
15+
}
16+
17+
@Getter
18+
public static class Summary {
19+
private Origin origin;
20+
private Destination destination;
21+
private List<Waypoint> waypoints; // ✅ 경유지(요청값)
22+
23+
private String priority;
24+
private Fare fare;
25+
26+
private int distance; // meters
27+
private int duration; // seconds
28+
}
29+
30+
@Getter
31+
public static class Origin {
32+
private String name;
33+
private double x;
34+
private double y;
35+
}
36+
37+
@Getter
38+
public static class Destination {
39+
private String name;
40+
private double x;
41+
private double y;
42+
}
43+
44+
@Getter
45+
public static class Waypoint {
46+
private String name;
47+
private double x;
48+
private double y;
49+
}
50+
51+
@Getter
52+
public static class Fare {
53+
private int taxi;
54+
private int toll;
55+
}
56+
57+
@Getter
58+
public static class Section {
59+
private List<Road> roads;
60+
private List<Guide> guides;
61+
}
62+
63+
@Getter
64+
public static class Road {
65+
private List<Double> vertexes;
66+
}
67+
68+
@Getter
69+
public static class Guide {
70+
private String name;
71+
private double x;
72+
private double y;
73+
private int distance;
74+
private int duration;
75+
private int type;
76+
private String guidance;
77+
private int road_index;
78+
}
79+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.back.web7_9_codecrete_be.domain.location.dto.response;
2+
3+
import lombok.Getter;
4+
5+
import java.util.List;
6+
@Getter
7+
public class TmapSummaryAllResponse {
8+
9+
private MetaData metaData;
10+
11+
// ===================== metaData =====================
12+
@Getter
13+
public static class MetaData {
14+
private Plan plan;
15+
private RequestParameters requestParameters;
16+
}
17+
18+
// ===================== plan =====================
19+
@Getter
20+
public static class Plan {
21+
private List<Itinerary> itineraries;
22+
}
23+
24+
// ===================== itineraries =====================
25+
@Getter
26+
public static class Itinerary {
27+
28+
private int pathType; // 경로 탐색 결과 종류
29+
private int totalTime; // 총 소요시간 (sec)
30+
private int transferCount; // 환승 횟수
31+
private int totalWalkDistance; // 총 보행 거리 (m)
32+
private int totalDistance; // 총 이동 거리 (m)
33+
private int totalWalkTime; // 총 보행 시간 (sec)
34+
35+
private Fare fare; // 요금 정보
36+
}
37+
38+
// ===================== fare =====================
39+
@Getter
40+
public static class Fare {
41+
private Regular regular;
42+
}
43+
44+
// ===================== regular =====================
45+
@Getter
46+
public static class Regular {
47+
private Currency currency;
48+
private int totalFare; // 대중교통 요금
49+
}
50+
51+
// ===================== currency =====================
52+
@Getter
53+
public static class Currency {
54+
private String symbol; // ₩
55+
private String currency; // 원
56+
private String currencyCode; // KRW
57+
}
58+
59+
// ===================== requestParameters =====================
60+
@Getter
61+
public static class RequestParameters {
62+
63+
private String reqDttm; // 요청 시각 (yyyymmddhhmiss)
64+
65+
private String startX; // 출발지 경도
66+
private String startY; // 출발지 위도
67+
private String endX; // 도착지 경도
68+
private String endY; // 도착지 위도
69+
}
70+
71+
}

0 commit comments

Comments
 (0)