From 0441683d557d417db704c8c4142b456aa20c2b33 Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Sat, 7 Feb 2026 17:01:56 +0530 Subject: [PATCH] Return uppercase country name list for country search API --- docs/API_REFERENCE.txt | 3 ++- .../controller/system/CountrySearch.kt | 19 +++---------------- .../repo/property/CountryReferenceRepo.kt | 12 +++--------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/docs/API_REFERENCE.txt b/docs/API_REFERENCE.txt index 691f5c0..5d6e888 100644 --- a/docs/API_REFERENCE.txt +++ b/docs/API_REFERENCE.txt @@ -157,7 +157,8 @@ AUTH + SYSTEM APIS - Searches countries from local country_reference table. - Case-insensitive match on country name, official name, ISO alpha-2, and ISO alpha-3. - - Example: q=IND returns matches like India and related country names. + - Returns JSON array of uppercase country names only. + - Example: q=IND can return ["INDIA", "INDONESIA", ...]. Request body: diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/system/CountrySearch.kt b/src/main/kotlin/com/android/trisolarisserver/controller/system/CountrySearch.kt index dbfa6fa..d9aa495 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/system/CountrySearch.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/system/CountrySearch.kt @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController import org.springframework.web.server.ResponseStatusException +import java.util.Locale @RestController class CountrySearch( @@ -16,7 +17,7 @@ class CountrySearch( fun searchCountries( @RequestParam("q") q: String, @RequestParam("limit", required = false, defaultValue = "20") limit: Int - ): List { + ): List { val query = q.trim() if (query.length < 3) { throw ResponseStatusException(HttpStatus.BAD_REQUEST, "q must be at least 3 characters") @@ -24,20 +25,6 @@ class CountrySearch( val boundedLimit = limit.coerceIn(1, 100) return countryReferenceRepo .searchCountries(query, PageRequest.of(0, boundedLimit)) - .map { - CountrySearchResponse( - name = it.name, - officialName = it.officialName, - isoAlpha2 = it.isoAlpha2, - isoAlpha3 = it.isoAlpha3 - ) - } + .map { it.name.uppercase(Locale.ROOT) } } } - -data class CountrySearchResponse( - val name: String, - val officialName: String?, - val isoAlpha2: String?, - val isoAlpha3: String? -) diff --git a/src/main/kotlin/com/android/trisolarisserver/repo/property/CountryReferenceRepo.kt b/src/main/kotlin/com/android/trisolarisserver/repo/property/CountryReferenceRepo.kt index 24b7a33..008d000 100644 --- a/src/main/kotlin/com/android/trisolarisserver/repo/property/CountryReferenceRepo.kt +++ b/src/main/kotlin/com/android/trisolarisserver/repo/property/CountryReferenceRepo.kt @@ -9,10 +9,7 @@ import org.springframework.data.repository.query.Param interface CountryReferenceRepo : JpaRepository { @Query( """ - select c.name as name, - c.officialName as officialName, - c.isoAlpha2 as isoAlpha2, - c.isoAlpha3 as isoAlpha3 + select c.name as name from CountryReference c where trim(c.name) <> '' and ( @@ -35,12 +32,9 @@ interface CountryReferenceRepo : JpaRepository { fun searchCountries( @Param("query") query: String, pageable: Pageable - ): List + ): List } -interface CountrySearchRow { +interface CountryNameRow { val name: String - val officialName: String? - val isoAlpha2: String? - val isoAlpha3: String? }