Last active
August 6, 2020 16:24
-
-
Save DenisBronx/77f4d7dd01eebf3c828a69b006b5ded6 to your computer and use it in GitHub Desktop.
Usecases
This file contains hidden or 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
// User | |
interface GetCurrentUserUseCase { | |
operator fun invoke(): Result<User> | |
} | |
class GetCurrentUserUseCaseImpl( | |
private val userRepository: UserRepository | |
) : GetCurrentUserUseCase { | |
override fun invoke(): Result<User> = userRepository.getUser() | |
} | |
// Transaction | |
interface GetUserTransactionsUseCase { | |
operator fun invoke(): Single<Result<List<Transaction>>> | |
} | |
class GetUserTransactionsUseCaseImpl( | |
private val getCurrentUserUseCase: GetCurrentUserUseCase, | |
private val transactionRepository: TransactionRepository | |
) : GetUserTransactionsUseCase { | |
override fun invoke(): Single<Result<List<Transaction>>> { | |
return when (val result = getCurrentUserUseCase()) { | |
is Result.Success -> transactionRepository.getUserTransactions(result.value) | |
is Result.Failure -> Single.just(Result.Failure(result.throwable)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment