Skip to content

Commit 7ef4e3b

Browse files
committed
Merge branch 'currency-refactor' into main
2 parents 972738b + 6d28976 commit 7ef4e3b

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

app/src/main/java/dev/shorthouse/coinwatch/data/mapper/CoinSearchResultsMapper.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package dev.shorthouse.coinwatch.data.mapper
22

3-
import dev.shorthouse.coinwatch.common.Mapper
43
import dev.shorthouse.coinwatch.data.source.remote.model.CoinSearchResultsApiModel
54
import dev.shorthouse.coinwatch.model.SearchCoin
65
import javax.inject.Inject
76

8-
class CoinSearchResultsMapper @Inject constructor() :
9-
Mapper<CoinSearchResultsApiModel, List<SearchCoin>> {
10-
override fun mapApiModelToModel(from: CoinSearchResultsApiModel): List<SearchCoin> {
11-
val validSearchResultsCoins = from.coinsSearchResultsData?.coinSearchResults
7+
class CoinSearchResultsMapper @Inject constructor() {
8+
fun mapApiModelToModel(apiModel: CoinSearchResultsApiModel): List<SearchCoin> {
9+
val validSearchResultsCoins = apiModel.coinsSearchResultsData?.coinSearchResults
1210
.orEmpty()
1311
.filterNotNull()
1412
.filter { it.id != null }
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.shorthouse.coinwatch.data.source.remote
22

3+
import dev.shorthouse.coinwatch.data.datastore.CoinSort
4+
import dev.shorthouse.coinwatch.data.datastore.Currency
35
import dev.shorthouse.coinwatch.data.source.remote.model.CoinChartApiModel
46
import dev.shorthouse.coinwatch.data.source.remote.model.CoinDetailsApiModel
57
import dev.shorthouse.coinwatch.data.source.remote.model.CoinSearchResultsApiModel
@@ -9,21 +11,37 @@ import retrofit2.Response
911
class FakeCoinNetworkDataSource(
1012
private val coinApi: CoinApi
1113
) : CoinNetworkDataSource {
12-
override suspend fun getCoins(coinIds: List<String>): Response<CoinsApiModel> {
13-
return coinApi.getCoins(coinIds = coinIds)
14+
override suspend fun getCoins(
15+
coinIds: List<String>,
16+
coinSort: CoinSort,
17+
currency: Currency
18+
): Response<CoinsApiModel> {
19+
return coinApi.getCoins(
20+
coinIds = coinIds,
21+
orderBy = coinSort.toOrderByString(),
22+
currencyUUID = currency.toCurrencyUUID()
23+
)
1424
}
1525

16-
override suspend fun getCoinDetails(coinId: String): Response<CoinDetailsApiModel> {
17-
return coinApi.getCoinDetails(coinId = coinId)
26+
override suspend fun getCoinDetails(
27+
coinId: String,
28+
currency: Currency
29+
): Response<CoinDetailsApiModel> {
30+
return coinApi.getCoinDetails(
31+
coinId = coinId,
32+
currencyUUID = currency.toCurrencyUUID()
33+
)
1834
}
1935

2036
override suspend fun getCoinChart(
2137
coinId: String,
22-
chartPeriod: String
38+
chartPeriod: String,
39+
currency: Currency
2340
): Response<CoinChartApiModel> {
2441
return coinApi.getCoinChart(
2542
coinId = coinId,
26-
chartPeriod = chartPeriod
43+
chartPeriod = chartPeriod,
44+
currencyUUID = currency.toCurrencyUUID()
2745
)
2846
}
2947

@@ -33,3 +51,20 @@ class FakeCoinNetworkDataSource(
3351
return coinApi.getCoinSearchResults(searchQuery = searchQuery)
3452
}
3553
}
54+
55+
private fun CoinSort.toOrderByString(): String {
56+
return when (this) {
57+
CoinSort.MarketCap -> "marketCap"
58+
CoinSort.Price -> "price"
59+
CoinSort.PriceChange24h -> "change"
60+
CoinSort.Volume24h -> "24hVolume"
61+
}
62+
}
63+
64+
private fun Currency.toCurrencyUUID(): String {
65+
return when (this) {
66+
Currency.USD -> "yhjMzLPhuIDl"
67+
Currency.GBP -> "Hokyui45Z38f"
68+
Currency.EUR -> "5k-_VTxqtCEI"
69+
}
70+
}

0 commit comments

Comments
 (0)