Skip to content

Commit

Permalink
[FEATURE] #30 Profile Starred 포함한 User 갱신
Browse files Browse the repository at this point in the history
  • Loading branch information
eshc123 committed Sep 29, 2022
1 parent f291bf1 commit 1780c75
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
24 changes: 16 additions & 8 deletions data/src/main/java/com/eshc/data/repository/UserRepositoryImpl.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,15 +37,22 @@ class UserRepositoryImpl @Inject constructor(

override fun getStarred(): Single<Result<Int>> {
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<String>(e)
Expand Down
2 changes: 1 addition & 1 deletion domain/src/main/java/com/eshc/domain/model/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

0 comments on commit 1780c75

Please sign in to comment.