Log geocode response in extracted data
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s

This commit is contained in:
androidlover5842
2026-01-31 11:07:15 +05:30
parent 41452ccd3d
commit b7b1975c5c
2 changed files with 22 additions and 7 deletions

View File

@@ -426,13 +426,19 @@ class DocumentExtractionService(
}
}
private fun applyBookingCityUpdates(document: GuestDocument, results: Map<String, String>) {
private fun applyBookingCityUpdates(document: GuestDocument, results: MutableMap<String, String>) {
val bookingId = document.booking?.id ?: return
val booking = bookingRepo.findById(bookingId).orElse(null) ?: return
if (booking.fromCity?.isNotBlank() == true && booking.toCity?.isNotBlank() == true) return
val pin = cleanedValue(results[DocumentPrompts.PIN_CODE.first]) ?: return
if (!isValidPin(pin)) return
val resolved = googleGeocodingClient.resolveCityState(pin) ?: return
val geocode = googleGeocodingClient.resolveCityState(pin)
geocode.status?.let { results["geoStatus"] = it }
if (geocode.rawResponse != null) {
results["geoResponse"] = geocode.rawResponse.take(4000)
}
val resolved = geocode.resolvedCityState ?: return
results["geoResolved"] = resolved
var updated = false
if (booking.fromCity.isNullOrBlank()) {
booking.fromCity = resolved

View File

@@ -18,8 +18,10 @@ class GoogleGeocodingClient(
) {
private val logger = LoggerFactory.getLogger(GoogleGeocodingClient::class.java)
fun resolveCityState(pinCode: String): String? {
if (apiKey.isBlank()) return null
fun resolveCityState(pinCode: String): GeocodeResult {
if (apiKey.isBlank()) {
return GeocodeResult(null, null, "NO_API_KEY")
}
return try {
val url = UriComponentsBuilder.fromUriString(baseUrl)
.queryParam("components", "postal_code:$pinCode|country:IN")
@@ -27,11 +29,12 @@ class GoogleGeocodingClient(
.queryParam("key", apiKey)
.toUriString()
val response = restTemplate.getForEntity(url, String::class.java)
val body = response.body ?: return null
parseCityState(body)
val body = response.body ?: return GeocodeResult(null, null, "EMPTY_BODY")
val parsed = parseCityState(body)
GeocodeResult(parsed, body, "OK")
} catch (ex: Exception) {
logger.warn("Geocoding failed: {}", ex.message)
null
GeocodeResult(null, null, "ERROR")
}
}
@@ -67,3 +70,9 @@ class GoogleGeocodingClient(
return listOfNotNull(preferredCity, state?.trim()?.ifBlank { null }).joinToString(", ")
}
}
data class GeocodeResult(
val resolvedCityState: String?,
val rawResponse: String?,
val status: String?
)