-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 주소 반환 API
- Loading branch information
Showing
13 changed files
with
128 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/cabin/plat/domain/address/controller/AddressController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.cabin.plat.domain.address.controller; | ||
|
||
import com.cabin.plat.config.AuthMember; | ||
import com.cabin.plat.domain.address.dto.AddressResponse; | ||
import com.cabin.plat.domain.address.service.AddressService; | ||
import com.cabin.plat.domain.member.entity.Member; | ||
import com.cabin.plat.global.common.BaseResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/address") | ||
@Tag(name = "주소 API", description = "주소, 위치 관련 API 입니다.") | ||
public class AddressController { | ||
private final AddressService addressService; | ||
|
||
@Operation(summary = "역지오코딩", description = "위도 경도를 받아서 해당 위치의 주소를 반환한다.") | ||
@GetMapping("/reverse-geocode") | ||
public BaseResponse<AddressResponse.AddressString> getAddress( | ||
@AuthMember Member member, | ||
@RequestParam double latitude, | ||
@RequestParam double longitude) { | ||
return BaseResponse.onSuccess(addressService.getAddress(latitude, longitude)); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/cabin/plat/domain/address/dto/AddressResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.cabin.plat.domain.address.dto; | ||
|
||
import lombok.*; | ||
|
||
public class AddressResponse { | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class AddressString { | ||
private String address; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/cabin/plat/domain/address/mapper/AddressMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.cabin.plat.domain.address.mapper; | ||
|
||
import com.cabin.plat.domain.address.dto.AddressResponse; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class AddressMapper { | ||
public AddressResponse.AddressString toAddressString( | ||
String address | ||
) { | ||
return AddressResponse.AddressString.builder() | ||
.address(address) | ||
.build(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/cabin/plat/domain/address/service/AddressService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.cabin.plat.domain.address.service; | ||
|
||
import com.cabin.plat.domain.address.dto.AddressResponse; | ||
import org.springframework.stereotype.Service; | ||
|
||
public interface AddressService { | ||
AddressResponse.AddressString getAddress(double latitude, double longitude); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/cabin/plat/domain/address/service/AddressServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.cabin.plat.domain.address.service; | ||
|
||
import com.cabin.plat.domain.address.dto.AddressResponse; | ||
import com.cabin.plat.domain.address.dto.AddressResponse.AddressString; | ||
import com.cabin.plat.domain.address.mapper.AddressMapper; | ||
import com.cabin.plat.global.util.geocoding.AddressInfo; | ||
import com.cabin.plat.global.util.geocoding.ReverseGeoCoding; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AddressServiceImpl implements AddressService { | ||
private final ReverseGeoCoding reverseGeoCoding; | ||
private final AddressMapper addressMapper; | ||
|
||
@Override | ||
public AddressResponse.AddressString getAddress(double latitude, double longitude) { | ||
AddressInfo addressInfo = reverseGeoCoding.getAddressInfo(latitude, longitude); | ||
return addressMapper.toAddressString(addressInfo.toAddress()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/java/com/cabin/plat/domain/address/service/AddressServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.cabin.plat.domain.address.service; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.cabin.plat.domain.address.dto.AddressResponse; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
class AddressServiceImplTest { | ||
|
||
@Autowired | ||
private AddressService addressService; | ||
|
||
@Test | ||
void 외부API_주소_받아오기_테스트() { | ||
// given | ||
double latitude = 36.014188; | ||
double longitude = 129.325802; | ||
|
||
AddressResponse.AddressString addressString = addressService.getAddress(latitude, longitude); | ||
assertThat(addressString.getAddress()).isEqualTo("경상북도 포항시 남구 지곡동"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters