Skip to content

Commit

Permalink
[FEATURE] #30 UserRepositoryImpl - user 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
eshc123 committed Sep 28, 2022
1 parent 68bb945 commit 7d3a9c6
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions data/src/main/java/com/eshc/data/repository/UserRepositoryImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ import javax.inject.Inject

class UserRepositoryImpl @Inject constructor(
private val userDataSource: UserDataSource
) : UserRepository{
) : UserRepository {
private var user: User? = null

override fun getUser(): Single<Result<User>> {
return try {
userDataSource.getUser()
.map {
Result.success(it.getOrThrow())
}
.onErrorReturn {
Result.failure(it.cause ?: Throwable())
}
} catch (e : Exception) {
Single.create {
try {
return if (user == null)
userDataSource.getUser()
.map {
it.getOrThrow().run {
user = this
Result.success(this)
}
}
.onErrorReturn {
Result.failure(it.cause ?: Throwable())
}
else Single.just (
Result.success(user ?: User())
)
} catch (e: Exception) {
return Single.create {
Result.failure<String>(e)
}
}
Expand Down

0 comments on commit 7d3a9c6

Please sign in to comment.