diff --git a/data/src/main/java/com/eshc/data/repository/UserRepositoryImpl.kt b/data/src/main/java/com/eshc/data/repository/UserRepositoryImpl.kt index 1a6b304..f67524f 100644 --- a/data/src/main/java/com/eshc/data/repository/UserRepositoryImpl.kt +++ b/data/src/main/java/com/eshc/data/repository/UserRepositoryImpl.kt @@ -1,5 +1,6 @@ package com.eshc.data.repository +import android.view.View import com.eshc.data.source.UserDataSource import com.eshc.domain.model.User import com.eshc.domain.repository.UserRepository @@ -36,15 +37,22 @@ class UserRepositoryImpl @Inject constructor( override fun getStarred(): Single> { try { - return userDataSource.getUserStarred() - .map { - it.getOrThrow().run { - Result.success(this) + return if(user?.starred == null) { + userDataSource.getUserStarred() + .map { + it.getOrThrow().run { + user = user?.copy( + starred = this + ) + Result.success(this) + } } - } - .onErrorReturn { - Result.failure(it.cause ?: Throwable()) - } + .onErrorReturn { + Result.failure(it.cause ?: Throwable()) + } + } else Single.just( + Result.success(user?.starred ?: 0) + ) } catch (e: Exception) { return Single.create { Result.failure(e) 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 17c451a..f775de0 100644 --- a/domain/src/main/java/com/eshc/domain/model/User.kt +++ b/domain/src/main/java/com/eshc/domain/model/User.kt @@ -12,6 +12,6 @@ data class User( val publicRepos : Int = 0, val followers : Int = 0, val following : Int = 0, - val starred : Int = 0 + val starred : Int? = null ) diff --git a/feature-profile/src/main/java/com/eshc/feature/profile/UserModel.kt b/feature-profile/src/main/java/com/eshc/feature/profile/UserModel.kt index 6dd5ac2..5ed1b7e 100644 --- a/feature-profile/src/main/java/com/eshc/feature/profile/UserModel.kt +++ b/feature-profile/src/main/java/com/eshc/feature/profile/UserModel.kt @@ -19,6 +19,17 @@ data class UserModel( fun User.toUserModel() : UserModel { return UserModel( - id, login, avatarUrl, name, blog, location, email, bio, publicRepos, followers, following,starred + id = id, + login = login, + avatarUrl = avatarUrl, + name = name, + blog = blog, + location = location, + email = email, + bio = bio, + publicRepos = publicRepos, + followers = followers, + following = following, + starred = starred ?: 0 ) }