-
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.
feat: Provide suggestions interactor
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
places/src/commonMain/kotlin/com/ngallazzi/places/data/SuggestionsInteractorImpl.kt
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,49 @@ | ||
package com.ngallazzi.places.data | ||
|
||
import com.ngallazzi.places.domain.Address | ||
import com.ngallazzi.places.domain.City | ||
import com.ngallazzi.places.domain.Country | ||
import com.ngallazzi.places.domain.PlacesDataSource | ||
import com.ngallazzi.places.domain.SuggestionsInteractor | ||
|
||
internal class SuggestionsInteractorImpl( | ||
private val placesDataSource: PlacesDataSource, | ||
) : SuggestionsInteractor { | ||
override suspend fun getCountrySuggestions( | ||
search: String, | ||
languageCode: String | ||
): Result<List<Country>> { | ||
return runCatching { | ||
val response = placesDataSource.searchCountry(name = search, languageCode).getOrThrow() | ||
val countries = response.predictions.map { Country(it.placeId, it.description) } | ||
countries | ||
} | ||
} | ||
|
||
override suspend fun getCitySuggestions( | ||
search: String, | ||
languageCode: String | ||
): Result<List<City>> { | ||
return runCatching { | ||
val response = | ||
placesDataSource.searchCity(name = search, languageCode).getOrThrow() | ||
val cities = | ||
response.predictions.map { City(it.placeId, it.structuredFormatting.mainText) } | ||
cities | ||
} | ||
} | ||
|
||
override suspend fun getAddressSuggestions( | ||
search: String, | ||
languageCode: String | ||
): Result<List<Address>> { | ||
return runCatching { | ||
val response = | ||
placesDataSource.searchAddress(address = search, languageCode) | ||
.getOrThrow() | ||
val predictions = | ||
response.predictions.map { Address(it.placeId, it.structuredFormatting.mainText) } | ||
predictions | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
places/src/commonMain/kotlin/com/ngallazzi/places/domain/SuggestionsInteractor.kt
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.ngallazzi.places.domain | ||
|
||
interface SuggestionsInteractor { | ||
suspend fun getCountrySuggestions(search: String, languageCode: String): Result<List<Country>> | ||
suspend fun getCitySuggestions( | ||
search: String, | ||
languageCode: String | ||
): Result<List<City>> | ||
|
||
suspend fun getAddressSuggestions( | ||
search: String, | ||
languageCode: String | ||
): Result<List<Address>> | ||
} |