Updated on 2026-08-14
This commit is contained in:
parent
b35a60098e
commit
bb7bef8ab7
5 changed files with 65 additions and 2 deletions
|
|
@ -0,0 +1,27 @@
|
|||
package com.tangem.domain.appcurrency
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.NonEmptyList
|
||||
import arrow.core.raise.catch
|
||||
import arrow.core.raise.either
|
||||
import arrow.core.raise.ensureNotNull
|
||||
import arrow.core.toNonEmptyListOrNull
|
||||
import com.tangem.domain.appcurrency.error.AvailableCurrenciesError
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.appcurrency.repository.AppCurrencyRepository
|
||||
|
||||
// TODO: Add tests
|
||||
class GetAvailableCurrenciesUseCase(
|
||||
private val appCurrencyRepository: AppCurrencyRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(): Either<AvailableCurrenciesError, NonEmptyList<AppCurrency>> = either {
|
||||
val currencies = catch({ appCurrencyRepository.getAvailableAppCurrencies() }) {
|
||||
raise(AvailableCurrenciesError.DataError(it))
|
||||
}
|
||||
|
||||
ensureNotNull(currencies.toNonEmptyListOrNull()) {
|
||||
AvailableCurrenciesError.CurrenciesIsEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.tangem.domain.appcurrency
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.appcurrency.repository.AppCurrencyRepository
|
||||
|
||||
// TODO: Add tests
|
||||
class SelectAppCurrencyUseCase(
|
||||
private val appCurrencyRepository: AppCurrencyRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(currencyCode: String): Either<Throwable, Unit> {
|
||||
return Either.catch { appCurrencyRepository.changeAppCurrency(currencyCode) }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.tangem.domain.appcurrency.error
|
||||
|
||||
sealed class AvailableCurrenciesError {
|
||||
|
||||
object CurrenciesIsEmpty : AvailableCurrenciesError()
|
||||
|
||||
data class DataError(val cause: Throwable) : AvailableCurrenciesError()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue