From a58aa7f828d4cc612d54a1dea4d9f056d4370aa8 Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 29 Sep 2022 13:00:17 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20#30=20GetUserWithStarredCountUseCas?= =?UTF-8?q?e=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/eshc/domain/model/User.kt | 3 +- .../eshc/domain/repository/UserRepository.kt | 2 ++ .../user/GetUserWithStarredCountUseCase.kt | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 domain/src/main/java/com/eshc/domain/usecase/user/GetUserWithStarredCountUseCase.kt diff --git a/domain/src/main/java/com/eshc/domain/model/User.kt b/domain/src/main/java/com/eshc/domain/model/User.kt index e7f47e7..17c451a 100644 --- a/domain/src/main/java/com/eshc/domain/model/User.kt +++ b/domain/src/main/java/com/eshc/domain/model/User.kt @@ -11,6 +11,7 @@ data class User( val bio : String = "", val publicRepos : Int = 0, val followers : Int = 0, - val following : Int = 0 + val following : Int = 0, + val starred : Int = 0 ) diff --git a/domain/src/main/java/com/eshc/domain/repository/UserRepository.kt b/domain/src/main/java/com/eshc/domain/repository/UserRepository.kt index b0b0aa5..05d7ac3 100644 --- a/domain/src/main/java/com/eshc/domain/repository/UserRepository.kt +++ b/domain/src/main/java/com/eshc/domain/repository/UserRepository.kt @@ -5,4 +5,6 @@ import io.reactivex.rxjava3.core.Single interface UserRepository { fun getUser() : Single> + + fun getStarred() : Single> } \ No newline at end of file diff --git a/domain/src/main/java/com/eshc/domain/usecase/user/GetUserWithStarredCountUseCase.kt b/domain/src/main/java/com/eshc/domain/usecase/user/GetUserWithStarredCountUseCase.kt new file mode 100644 index 0000000..e25818c --- /dev/null +++ b/domain/src/main/java/com/eshc/domain/usecase/user/GetUserWithStarredCountUseCase.kt @@ -0,0 +1,31 @@ +package com.eshc.domain.usecase.user + +import com.eshc.domain.model.User +import com.eshc.domain.repository.UserRepository +import io.reactivex.rxjava3.core.Single +import javax.inject.Inject + +class GetUserWithStarredCountUseCase @Inject constructor( + private val userRepository: UserRepository, + private val getUserProfileUseCase: GetUserProfileUseCase +) { + operator fun invoke() : Single> { + return try { + userRepository.getStarred() + .zipWith(getUserProfileUseCase()){ starred, user -> + Result.success( + user.getOrThrow().copy( + starred = starred.getOrThrow() + ) + ) + } + .onErrorReturn { + Result.failure(it.cause ?: Throwable()) + } + } catch (e : Exception) { + Single.create { + Result.failure(e) + } + } + } +} \ No newline at end of file