Skip to content

Commit 475d017

Browse files
Merge pull request #276 from prgrms-web-devcourse-final-project/feat/#263
[Location] 경유지가 없을때 출력 가능 및 택시요금 추가
2 parents 2dce107 + 5b3d1a8 commit 475d017

5 files changed

Lines changed: 85 additions & 12 deletions

File tree

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

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.util.ArrayList;
3030
import java.util.List;
31+
import java.util.Map;
3132

3233
@Tag(name = "Location - Kakao", description = "카카오 로컬 API 연동(주변 음식점 조회, 좌표→주소 변환) 관련 엔드포인트")
3334
@RestController
@@ -45,10 +46,10 @@ public class KakaoApiController {
4546
)
4647
@PostMapping("/restaurant")
4748
public List<KakaoLocalResponse.Document> KakaoRestaurants(
48-
@RequestParam double lat,
49-
@RequestParam double lon
49+
@RequestParam double x,
50+
@RequestParam double y
5051
) {
51-
return kakaoLocalService.searchNearbyRestaurants(lat, lon);
52+
return kakaoLocalService.searchNearbyRestaurants(x, y);
5253
}
5354

5455

@@ -59,10 +60,10 @@ public List<KakaoLocalResponse.Document> KakaoRestaurants(
5960
)
6061
@PostMapping("/cafes")
6162
public List<KakaoLocalResponse.Document> KakaoCafes(
62-
@RequestParam double lat,
63-
@RequestParam double lon
63+
@RequestParam double x,
64+
@RequestParam double y
6465
) {
65-
return kakaoLocalService.searchNearbyCafes(lat, lon);
66+
return kakaoLocalService.searchNearbyCafes(x, y);
6667
}
6768

6869

@@ -190,7 +191,31 @@ public KakaoRouteSectionFeResponse navigateOnlyGuides(
190191
)
191192
@RequestBody KakaoRouteTransitRequest req
192193
) {
193-
194+
boolean isWayPointsExist = (req.getWaypoints() == null || req.getWaypoints().isEmpty());
195+
196+
if(!isWayPointsExist){
197+
KakaoMobilityResponse.Summary summary = navigateSummary(req.getOrigin().getX(), req.getOrigin().getY(), req.getDestination().getX(), req.getDestination().getY());
198+
List<KakaoRouteFeResponse> sections = List.of(
199+
new KakaoRouteFeResponse(
200+
0,
201+
summary.getDistance(),
202+
summary.getDuration(),
203+
Map.of("x", req.getOrigin().getX(), "y", req.getOrigin().getY()),
204+
Map.of("x", req.getDestination().getX(), "y", req.getDestination().getY())
205+
)
206+
);
207+
int totalTaxi = 0;
208+
if (summary.getFare() != null) {
209+
totalTaxi = summary.getFare().getTaxi();
210+
}
211+
return new KakaoRouteSectionFeResponse(
212+
summary.getDistance(),
213+
summary.getDuration(),
214+
totalTaxi,
215+
sections
216+
217+
);
218+
}
194219
KakaoRouteTransitResponse res = kakaoLocalService.NaviSearchTransit(req);
195220
KakaoRouteTransitResponse.Route route = res.getRoutes().get(0);
196221

@@ -227,10 +252,14 @@ public KakaoRouteSectionFeResponse navigateOnlyGuides(
227252
int totalDuration = route.getSections().stream()
228253
.mapToInt(KakaoRouteTransitResponse.Section::getDuration)
229254
.sum();
230-
255+
int totalTaxi = 0;
256+
if (summary.getFare() != null) {
257+
totalTaxi = summary.getFare().getTaxi();
258+
}
231259
return new KakaoRouteSectionFeResponse(
232260
totalDistance,
233261
totalDuration,
262+
totalTaxi,
234263
sections
235264
);
236265
}

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,40 @@ public class TmapApiController {
4242
)
4343
)
4444
)
45-
@GetMapping("/tmap/transit")
45+
@GetMapping("/tmap/summary")
46+
public TmapSummaryAllResponse getSummary(
47+
48+
@Parameter(
49+
description = "출발지 경도 (longitude)",
50+
example = "126.9780",
51+
required = true
52+
)
53+
@RequestParam double startX,
54+
55+
@Parameter(
56+
description = "출발지 위도 (latitude)",
57+
example = "37.5665",
58+
required = true
59+
)
60+
@RequestParam double startY,
61+
62+
@Parameter(
63+
description = "도착지 경도 (longitude)",
64+
example = "127.0276",
65+
required = true
66+
)
67+
@RequestParam double endX,
68+
69+
@Parameter(
70+
description = "도착지 위도 (latitude)",
71+
example = "37.4979",
72+
required = true
73+
)
74+
@RequestParam double endY
75+
) {
76+
return tmapService.getSummaryRoute(startX, startY, endX, endY);
77+
}
78+
@GetMapping("/tmap/route")
4679
public String getTransit(
4780

4881
@Parameter(
@@ -75,7 +108,6 @@ public String getTransit(
75108
) {
76109
return tmapService.getRoute(startX, startY, endX, endY);
77110
}
78-
79111
@Operation(
80112
summary = "Tmap 도보만 경로 요약",
81113
description = "출발지와 도착지 좌표를 기준으로 Tmap 도보 경로의 총 거리와 소요 시간을 반환합니다."

src/main/java/com/back/web7_9_codecrete_be/domain/location/dto/fe/KakaoRouteSectionFeResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class KakaoRouteSectionFeResponse {
1717
@Schema(description = "전체 소요 시간 (second)", example = "3200")
1818
private int totalDuration;
1919

20+
@Schema(description = "택시비", example = "12000")
21+
private int totalTaxi; //택시비 추가
22+
2023
@Schema(description = "구간(section) 목록")
2124
private List<KakaoRouteFeResponse> sections;
2225
}

src/main/java/com/back/web7_9_codecrete_be/domain/location/dto/response/kakao/KakaoMobilityResponse.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,17 @@ public static class Summary {
3535

3636
@Schema(description = "총 소요 시간 (second)", example = "540")
3737
private int duration;
38+
39+
@Schema(description = "요금 정보")
40+
private Fare fare;
3841
}
42+
@Getter
43+
@Schema(description = "요금 정보")
44+
public static class Fare {
3945

46+
@Schema(description = "택시 요금 (원)", example = "12000")
47+
private int taxi;
48+
}
4049
@Getter
4150
@Schema(description = "경로 구간")
4251
public static class Section {

src/main/java/com/back/web7_9_codecrete_be/domain/location/service/KakaoLocalService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public List<KakaoLocalResponse.Document> searchNearbyRestaurants(double lat, dou
2929
.path("/v2/local/search/keyword.json")
3030
.queryParam("query", "음식점")
3131
.queryParam("category_group_code", "FD6")
32-
.queryParam("y", lat)
3332
.queryParam("x", lng)
33+
.queryParam("y", lat)
3434
.queryParam("radius", 1000) // 반경 1km
3535
.queryParam("sort", "distance")
3636
.build()
@@ -48,8 +48,8 @@ public List<KakaoLocalResponse.Document> searchNearbyCafes(double lat, double ln
4848
.path("/v2/local/search/keyword.json")
4949
.queryParam("query", "카페")
5050
.queryParam("category_group_code", "CE7")
51-
.queryParam("y", lat)
5251
.queryParam("x", lng)
52+
.queryParam("y", lat)
5353
.queryParam("radius", 1000) // 반경 1km
5454
.queryParam("sort", "distance")
5555
.build()

0 commit comments

Comments
 (0)