Skip to content

Commit

Permalink
[FEATURE] #30 GetUserWithStarredCountUseCase 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
eshc123 committed Sep 29, 2022
1 parent 0713242 commit a58aa7f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion domain/src/main/java/com/eshc/domain/model/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import io.reactivex.rxjava3.core.Single

interface UserRepository {
fun getUser() : Single<Result<User>>

fun getStarred() : Single<Result<Int>>
}
Original file line number Diff line number Diff line change
@@ -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<Result<User>> {
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<String>(e)
}
}
}
}

0 comments on commit a58aa7f

Please sign in to comment.