Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Lemon 좌표 자동완성 버그 수정 #200

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ data class OriginPlace(
val address: String? = null,
val phoneNumber: String? = null,
val starGrade: Double? = null,
val longitude: Double?,
val latitude: Double?,
var longitude: Double?,
var latitude: Double?,
val reviewCount: Int,
val category: String?,
val openingHours: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,41 @@ import org.springframework.web.client.body
class LemonPlaceAutoCompleteAdapter(
private val lemonOriginMapIdParserStrategy: LemonOriginMapIdParserStrategy,
private val lemonApiClient: RestClient,
private val lemonCoordinateApiClient: RestClient,
) : OriginPlaceAutoCompletePort {
override fun isAutoCompleteSupportedUrl(url: String): Boolean {
return lemonOriginMapIdParserStrategy.getParserBySupportedUrl(url) != null
}
override fun isAutoCompleteSupportedUrl(url: String): Boolean =
lemonOriginMapIdParserStrategy.getParserBySupportedUrl(url) != null

override fun extractOriginMapId(url: String): OriginMapId {
return lemonOriginMapIdParserStrategy.getParserBySupportedUrl(url)?.parseOriginMapId(url)
override fun extractOriginMapId(url: String): OriginMapId =
lemonOriginMapIdParserStrategy.getParserBySupportedUrl(url)?.parseOriginMapId(url)
?: throw PiikiiException(ExceptionCode.NOT_SUPPORT_AUTO_COMPLETE_URL)
}

override fun getAutoCompletedPlace(
url: String,
originMapId: OriginMapId,
): OriginPlace {
return lemonApiClient.get()
.uri("/${originMapId.toId()}")
.retrieve()
.body<LemonPlaceInfoResponse>()
?.toOriginPlace(url)
?: throw PiikiiException(
exceptionCode = ExceptionCode.URL_PROCESS_ERROR,
detailMessage = "origin: lemon, url : $url",
)
val originPlace =
lemonApiClient.get()
.uri("/${originMapId.toId()}")
.retrieve()
.body<LemonPlaceInfoResponse>()
?.toOriginPlace(url)
?: throw PiikiiException(
exceptionCode = ExceptionCode.URL_PROCESS_ERROR,
detailMessage = "origin: lemon, url: $url",
)

val lemonCoordinateResponse =
lemonCoordinateApiClient.get()
.uri { it.queryParam("query", originPlace.address).build() }
.retrieve()
.body<LemonCoordinateResponse>()

lemonCoordinateResponse?.documents?.let { document ->
originPlace.longitude = document.firstOrNull()?.x?.toDouble()
originPlace.latitude = document.firstOrNull()?.y?.toDouble()
}

return originPlace
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,53 @@ data class LemonPlaceInfoResponse(
val orgurl: String?,
)
}

data class LemonCoordinateResponse(
val documents: List<Document>,
val meta: Meta,
)

data class Document(
val address: Address,
@JsonProperty("address_name") val addressName: String,
@JsonProperty("address_type") val addressType: String,
@JsonProperty("road_address") val roadAddress: RoadAddress,
val x: String,
val y: String,
)

data class Address(
@JsonProperty("address_name") val addressName: String,
@JsonProperty("b_code") val bCode: String,
@JsonProperty("h_code") val hCode: String,
@JsonProperty("main_address_no") val mainAddressNo: String,
@JsonProperty("mountain_yn") val mountainYn: String,
@JsonProperty("region_1depth_name") val region1depthName: String,
@JsonProperty("region_2depth_name") val region2depthName: String,
@JsonProperty("region_3depth_h_name") val region3depthHName: String,
@JsonProperty("region_3depth_name") val region3depthName: String,
@JsonProperty("sub_address_no") val subAddressNo: String,
val x: String,
val y: String,
)

data class RoadAddress(
@JsonProperty("address_name") val addressName: String,
@JsonProperty("building_name") val buildingName: String,
@JsonProperty("main_building_no") val mainBuildingNo: String,
@JsonProperty("region_1depth_name") val region1depthName: String,
@JsonProperty("region_2depth_name") val region2depthName: String,
@JsonProperty("region_3depth_name") val region3depthName: String,
@JsonProperty("road_name") val roadName: String,
@JsonProperty("sub_building_no") val subBuildingNo: String,
@JsonProperty("underground_yn") val undergroundYn: String,
val x: String,
val y: String,
@JsonProperty("zone_no") val zoneNo: String,
)

data class Meta(
@JsonProperty("is_end") val isEnd: Boolean,
@JsonProperty("pageable_count") val pageableCount: Int,
@JsonProperty("total_count") val totalCount: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.web.client.RestClient

@Configuration
@EnableConfigurationProperties(LemonProperties::class)
class LemonConfig {
@EnableConfigurationProperties(LemonProperties::class, LemonCoordinateProperties::class)
open class LemonConfig {
@Bean
fun lemonApiClient(lemonProperties: LemonProperties): RestClient {
open fun lemonApiClient(lemonProperties: LemonProperties): RestClient {
return RestClient.builder()
.baseUrl(lemonProperties.url.api)
.build()
}

@Bean
open fun lemonCoordinateApiClient(lemonCoordinateProperties: LemonCoordinateProperties): RestClient {
return RestClient.builder()
.defaultHeader(HttpHeaders.AUTHORIZATION, lemonCoordinateProperties.auth)
.baseUrl(lemonCoordinateProperties.url)
.build()
}
}

@ConfigurationProperties(prefix = "lemon")
Expand All @@ -32,3 +41,9 @@ data class LemonUrl(
val mobileApp: String,
)
}

@ConfigurationProperties(prefix = "coordinate-api")
data class LemonCoordinateProperties(
val url: String,
val auth: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ lemon:
mobile-web: ${LEMON_MOBILE_WEB_URL_REGEX}
mobile-app: ${LEMON_MOBILE_APP_URL_REGEX}
api: ${LEMON_API_URL}

coordinate-api:
url: ${LEMON_COORDINATE_API_URL}
auth: ${LEMON_API_KEY}