diff --git a/src/main/java/com/kusitms/jipbap/user/UserAddressService.java b/src/main/java/com/kusitms/jipbap/user/UserAddressService.java index 0ab702f..b7afca1 100644 --- a/src/main/java/com/kusitms/jipbap/user/UserAddressService.java +++ b/src/main/java/com/kusitms/jipbap/user/UserAddressService.java @@ -15,6 +15,7 @@ import org.springframework.web.client.RestTemplate; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; @Slf4j @@ -106,22 +107,21 @@ private PostalAddressDto findPostalAddress(GeocodingAddressDto geocodingAddressD try { String formattedAddress = geocodingAddressDto.getFormattedAddress(); // 실제 데이터베이스에 저장할 주소 - Double lat = geocodingAddressDto.getGeometry().getLocation().getLat(); - Double lng = geocodingAddressDto.getGeometry().getLocation().getLng(); - String countryName = null; String postalCode = null; + for (AddressComponentDto addressComponent : geocodingAddressDto.getAddressComponentList()) { List types = addressComponent.getTypes(); + if (types != null && types.contains("country")) { countryName = addressComponent.getLongName(); } if (types != null && types.contains("postal_code")) { postalCode = addressComponent.getLongName(); } - else{ - throw new PostalCodeNotFoundException("우편번호를 찾을 수 없습니다. 주소를 다시 입력해주세요."); - } + } + if (postalCode == null || postalCode.isEmpty()){ + throw new PostalCodeNotFoundException("우편번호를 찾을 수 없습니다. 주소를 다시 입력해주세요."); } return new PostalAddressDto(formattedAddress, postalCode); } catch (NullPointerException e) { diff --git a/src/main/java/com/kusitms/jipbap/user/dto/geolocation/AddressComponentDto.java b/src/main/java/com/kusitms/jipbap/user/dto/geolocation/AddressComponentDto.java index 4fbb7ec..9c176d5 100644 --- a/src/main/java/com/kusitms/jipbap/user/dto/geolocation/AddressComponentDto.java +++ b/src/main/java/com/kusitms/jipbap/user/dto/geolocation/AddressComponentDto.java @@ -15,5 +15,6 @@ public class AddressComponentDto { @JsonProperty("short_name") private String shortName; + @JsonProperty("types") private List types; } \ No newline at end of file