Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradle.kotlin.dsl.implementation

plugins {
java
id("org.springframework.boot") version "3.5.8"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.back.web7_9_codecrete_be.domain.location.controller;

import com.back.web7_9_codecrete_be.domain.location.dto.KakaoLocalResponse;
import com.back.web7_9_codecrete_be.domain.location.service.KakaoLocalService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/test")
@RequiredArgsConstructor
public class KakaoTestController {

private final KakaoLocalService kakaoLocalService;

@GetMapping("/kakao-restaurants")
public List<KakaoLocalResponse.Document> testKakaoRestaurants() {

// ✅ 테스트용 하드코딩 좌표 (서울 시청 근처)
double lat = 37.5665;
double lng = 126.9780;

return kakaoLocalService.searchNearbyRestaurants(lat, lng);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.back.web7_9_codecrete_be.domain.location.controller;

import com.back.web7_9_codecrete_be.domain.location.service.TmapService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/tmap")
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.

URL 에 v1 추가해주시면 감사하겠습니당

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.

넵! 까먹고 있었는데 말씀해주셔서 감사합니다

public class TmapController {

private final TmapService tmapService;

@GetMapping("/transit")
public String getTransit(
@RequestParam double startX,
@RequestParam double startY,
@RequestParam double endX,
@RequestParam double endY
) {
return tmapService.getRoute(startX, startY, endX, endY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.back.web7_9_codecrete_be.domain.location.dto;

import lombok.Data;

import java.util.List;

@Data
public class KakaoLocalResponse {
private List<Document> documents;

@Data
public static class Document {
private String place_name;
private String x; // longitude
private String y; // latitude
private String road_address_name;
private String address_name;
private String place_url;
}
}
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.Data;

@Data
public class TmapResponse {

private String startX;
private String startY;
private String endX;
private String endY;
private int count; //최대 응답 결과 개수
private String format; //출력포멧 : jsom, xml

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

import com.back.web7_9_codecrete_be.domain.location.dto.KakaoLocalResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.List;

@Service
@RequiredArgsConstructor
public class KakaoLocalService {

private final WebClient kakaoWebClient;

public List<KakaoLocalResponse.Document> searchNearbyRestaurants(double lat, double lng) {

return kakaoWebClient.get()
.uri(uriBuilder -> uriBuilder
.path("/v2/local/search/keyword.json")
.queryParam("query", "음식점")
.queryParam("y", lat)
.queryParam("x", lng)
.queryParam("radius", 1000) // 반경 1km
.build()
)
.retrieve()
.bodyToMono(KakaoLocalResponse.class)
.block() // 동기 호출 (필요하면 비동기로 변경 가능)
.getDocuments();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.back.web7_9_codecrete_be.domain.location.service;

import com.back.web7_9_codecrete_be.domain.location.dto.KakaoLocalResponse;
import com.back.web7_9_codecrete_be.domain.location.dto.TmapResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

@Service
@RequiredArgsConstructor
public class TmapService {

private final WebClient TmapClient;

public String getRoute(double startX, double startY, double endX, double endY) {

TmapResponse request = new TmapResponse();
request.setStartX(String.valueOf(startX));
request.setStartY(String.valueOf(startY));
request.setEndX(String.valueOf(endX));
request.setEndY(String.valueOf(endY));
request.setFormat("json");
request.setCount(5);

return TmapClient.post()
.uri("/transit/routes")
.bodyValue(request)
.retrieve()
.bodyToMono(String.class)
.block();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class WebClientConfig {
@Value("${mailgun.domain}")
private String mailgunDomain;

@Value("${tmap.api-key}")
private String tmapApiKey;

@Value("${kakao.restapi-key}")
private String kakaomapApiKey;

@Bean
public WebClient mailgunClient() {
String auth = "api:" + mailgunApiKey;
Expand All @@ -39,4 +45,21 @@ public WebClient mailgunClient() {
public RestTemplate restTemplate() {
return new RestTemplate();
}

@Bean
public WebClient kakaoWebClient() {
return WebClient.builder()
.baseUrl("https://dapi.kakao.com")
.defaultHeader("Authorization", kakaomapApiKey)
.build();
}


@Bean
public WebClient TmapClient(){
return WebClient.builder()
.baseUrl("https://apis.openapi.sk.com")
.defaultHeader("appKey", tmapApiKey)
.build();
}
}
6 changes: 6 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ jwt:
secret: ${SECRET_KEY}
access-token-expiration: 3600 # 1시간
refresh-token-expiration: 1209600 # 14일

tmap: #Tmap 대중교통 추천 api 키
api-key: ${TMAP_API_KEY}

kakao: #Kakao map REST API 키
restapi-key: ${KAKAOMAP_API_KEY}

This file was deleted.

Loading