Skip to content

Commit

Permalink
Merge pull request #2 from Mindera/feature/MKMPT-2_Change_API_To_Exch…
Browse files Browse the repository at this point in the history
…angerates

MKMPT-2_Change_API_To_Exchangerates
  • Loading branch information
pawanmindera authored Apr 10, 2024
2 parents 6958be5 + 45b5f07 commit 2e14eb3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@ import com.mindera.kmpexample.launches.domain.model.CurrencyExchangeResponseItem
@Composable
fun CurrencyExchangeScreen(
modifier: Modifier = Modifier,
launches: ImmutableList<CurrencyExchangeResponseItem>,
currencies: ImmutableList<CurrencyExchangeResponseItem>,
) {
val lazyListState = rememberLazyListState()

if (launches.isNotEmpty()) {
if (currencies.isNotEmpty()) {
LazyColumn(
modifier = modifier.fillMaxWidth(),
state = lazyListState,
) {
itemsIndexed(items = launches[0].rates, key = { index, _ -> index }) { index, launch ->

if (index != 0) {
Divider(thickness = 2.dp)
currencies.forEach {
itemsIndexed(items = it.rates, key = { index, _ -> index }) { index, launch ->
if (index != 0) {
Divider(thickness = 2.dp)
}
Text(it.no)
Text(launch.id)
Text(launch.currency.replaceFirstChar {
if (it.isLowerCase()) it.titlecase() else it.toString()
})
Text(launch.code, color = Color.Blue)
Text(launch.currencyRate.toString(), color = Color.Gray)
}
Text(launch.id)
Text(launch.currency.replaceFirstChar {
if (it.isLowerCase()) it.titlecase() else it.toString()
})
Text(launch.code, color = Color.Blue)
Text(launch.currencyRate.toString(), color = Color.Gray)
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class KtorCurrencyExchangeRemoteSource constructor(
private val client: HttpClient,
) : CurrencyExchangeRemoteSource {


override suspend fun getCurrencyExchange(): List<DomainCurrencyExchangeResponseItem> =
getCurrencyExchange("A").zip(getCurrencyExchange("B")) { listA, listB ->
DomainCurrencyExchangeResponseItem(listA.rates + listB.rates)
}
getCurrencyExchange("A/last/10/")

private suspend fun getCurrencyExchange(table: String): List<DomainCurrencyExchangeResponseItem> =
client.get("$baseUrl/$table")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.mindera.uuid

internal fun CurrencyExchangeResponseItem.toDomain() =
com.mindera.kmpexample.launches.domain.model.CurrencyExchangeResponseItem(
table = table,
no = no,
effectiveDate = effectiveDate,
rates = rates.map { it.toDomain() },
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ data class RatesItem(
@Serializable
data class CurrencyExchangeResponseItem(

@SerialName("table")
val table: String,

@SerialName("no")
val no: String,

@SerialName("effectiveDate")
val effectiveDate: String,

@SerialName("rates")
val rates: List<RatesItem>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ data class RatesItem(

data class CurrencyExchangeResponseItem(

val table: String,

val no: String,

val effectiveDate: String,

val rates: List<RatesItem>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun CurrencyExchangeScene(onBack: (() -> Unit)) {
fontSize = 40.sp,
)
CurrencyExchangeScreen(
launches = state.value.launches
currencies = state.value.launches
)
}
}

0 comments on commit 2e14eb3

Please sign in to comment.