diff --git a/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java b/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java index 96b99ad..22b0360 100644 --- a/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java +++ b/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java @@ -23,7 +23,7 @@ public class LocationController { @ApiOperation(value = "위도, 경도를 주소로 바꾸는 함수") @GetMapping("/convert/geo") - public Map getAddressByGeo(@RequestParam BigDecimal lat, @RequestParam BigDecimal lng) { + public LocationPartDto.Address getAddressByGeo(@RequestParam BigDecimal lat, @RequestParam BigDecimal lng) { return locationService.convertGeoToAddressRT(String.valueOf(lat), String.valueOf(lng)); } diff --git a/src/main/java/com/mpnp/baechelin/api/dto/LocationPartDto.java b/src/main/java/com/mpnp/baechelin/api/dto/LocationPartDto.java index 8cf44eb..bfdba51 100644 --- a/src/main/java/com/mpnp/baechelin/api/dto/LocationPartDto.java +++ b/src/main/java/com/mpnp/baechelin/api/dto/LocationPartDto.java @@ -12,7 +12,7 @@ public class LocationPartDto { @Builder public static class LatLong{ @Builder.Default - private boolean status = true; + private boolean status = false; private String latitude; private String longitude; @@ -20,4 +20,13 @@ public boolean validate() { return this.latitude != null && this.longitude != null; } } + + @AllArgsConstructor + @Getter @Setter + @Builder + public static class Address{ + @Builder.Default + private boolean status = false; + private String address; + } } diff --git a/src/main/java/com/mpnp/baechelin/api/service/LocationService.java b/src/main/java/com/mpnp/baechelin/api/service/LocationService.java index c91d4f5..19ac6e8 100644 --- a/src/main/java/com/mpnp/baechelin/api/service/LocationService.java +++ b/src/main/java/com/mpnp/baechelin/api/service/LocationService.java @@ -34,7 +34,7 @@ public class LocationService { * @param address 주소 * @return LocationKeywordSearchForm의 규격에 맞는 결과 하나를 가져옴 */ - public LocationKeywordSearchForm getLatLngByAddressWC(String address) { + public LocationKeywordSearchForm convertAddressToGeoWC(String address) { WebClient client = WebClient.builder() .baseUrl("https://dapi.kakao.com/v2/local/search/keyword.json") .defaultUriVariables(Collections.singletonMap("url", "https://dapi.kakao.com/v2/local/search/keyword.json")) @@ -280,7 +280,7 @@ private String categoryFilter(String category) { * @param lng 경도 * @return 위도, 경도를 카카오맵 API(RestTemplate)를 통해 주소로 변환 후 Map에 넣어 반환 */ - public Map convertGeoToAddressRT(String lat, String lng) { + public LocationPartDto.Address convertGeoToAddressRT(String lat, String lng) { HttpHeaders headers = new HttpHeaders(); headers.setAccept(List.of(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); @@ -298,18 +298,21 @@ public Map convertGeoToAddressRT(String lat, String lng) { uri, HttpMethod.GET, new HttpEntity<>(headers), LocationAddressSearchForm.class ); LocationAddressSearchForm locationKeywordSearchForm = resultRe.getBody(); - Map map = new HashMap<>(); - if (locationKeywordSearchForm == null) { - map.put("status", false); - } else { - LocationAddressSearchForm.TotalAddress address = Arrays.stream(locationKeywordSearchForm.getDocuments()).findFirst().orElse(null); - if (address != null) { - map.put("address", address.getAddress().getAddress_name()); - map.put("status", true); - } else { - map.put("status", false); - } + return formToDto(locationKeywordSearchForm); + } + + private LocationPartDto.Address formToDto(LocationAddressSearchForm resultRe) { + LocationPartDto.Address addressInfoDto = LocationPartDto.Address.builder().build(); + if (resultRe == null) { + return addressInfoDto; + } + LocationAddressSearchForm.TotalAddress address = Arrays.stream(resultRe.getDocuments()).findFirst().orElse(null); + if (address != null) { + addressInfoDto = LocationPartDto.Address.builder() + .address(address.getAddress().getAddress_name()) + .status(true) + .build(); } - return map; + return addressInfoDto; } }