Skip to content

Commit

Permalink
✨ linkTo 변환 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
이용홍 committed Mar 20, 2023
1 parent 1ebbe17 commit 0c5fbe0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/main/kotlin/herbaccara/map/KaKaoMapService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package herbaccara.map
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import herbaccara.map.model.kakao.AnalyzeType
import herbaccara.map.model.kakao.Document
import herbaccara.map.model.kakao.SearchResult
import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.http.HttpRequest
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.ClientHttpResponse
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.web.client.getForObject
import org.springframework.web.util.UriComponentsBuilder

Expand All @@ -28,6 +30,11 @@ class KaKaoMapService(

protected val restTemplate = RestTemplateBuilder()
.rootUri(baseUrl)
.messageConverters(
listOf(
MappingJackson2HttpMessageConverter(objectMapper)
)
)
.additionalInterceptors(object : ClientHttpRequestInterceptor {
override fun intercept(
request: HttpRequest,
Expand All @@ -42,6 +49,14 @@ class KaKaoMapService(
})
.build()

fun linkTo(name: String, latitude: Double, longitude: Double): String {
return "https://map.kakao.com/link/to/$name,$latitude,$longitude"
}

fun linkTo(doc: Document): String {
return linkTo(doc.addressName, doc.y, doc.x)
}

@JvmOverloads
fun search(query: String, page: Int = 1, size: Int = 10, analyzeType: AnalyzeType? = null): SearchResult {
val uri = UriComponentsBuilder
Expand Down
6 changes: 1 addition & 5 deletions src/main/kotlin/herbaccara/map/model/kakao/Document.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ data class Document(
@field:JsonProperty("road_address") val roadAddress: RoadAddress,
val x: Double,
val y: Double
) {
fun toLink(): String {
return "https://map.kakao.com/link/to/${addressName},${y},${x}"
}
}
)
2 changes: 1 addition & 1 deletion src/test/kotlin/herbaccara/map/KaKaoMapServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class KaKaoMapServiceTest {
@Test
fun search() {
val search = kaKaoMapService.search("송파구 송파동 86-17")
val toLink = search.documents.first().toLink()
val toLink = kaKaoMapService.linkTo(search.documents.first())
println(toLink)
}
}
1 change: 1 addition & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
map:
kakao:
api-key:
fail-on-unknown-properties: true
logging:
level:
root: info
Expand Down

0 comments on commit 0c5fbe0

Please sign in to comment.