Skip to content

Commit

Permalink
Improved dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
armcha committed Nov 13, 2017
1 parent 65b3241 commit e188ab3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class UserDataRepository(

override fun getToken(authCode: String): Flowable<TokenResponse> = authApiService.getToken(authCode)

override fun saveToken(token: String?) {
preferences.saveUserToken(token)
}

override fun getUser(): Flowable<User> {
return userApiService.getUser().map {
mapper.translate(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.armcha.ribble.domain.interactor

import io.armcha.ribble.data.repository.ShotDataRepository
import io.armcha.ribble.di.scope.PerActivity
import io.armcha.ribble.domain.entity.Comment
import io.armcha.ribble.domain.fetcher.result_listener.RequestType
Expand All @@ -14,9 +13,7 @@ import javax.inject.Inject
@PerActivity
class CommentInteractor @Inject constructor(private val shotRepository: ShotRepository) {

fun getComments(shotId: String): Single<List<Comment>> {
return shotRepository.getShotComments(shotId)
}
fun getComments(shotId: String) = shotRepository.getShotComments(shotId)

fun deleteCommentsCache() {
shotRepository.deleteCacheFor(RequestType.COMMENTS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.armcha.ribble.domain.interactor

import io.armcha.ribble.data.repository.ShotDataRepository
import io.armcha.ribble.di.scope.PerActivity
import io.armcha.ribble.domain.entity.Like
import io.armcha.ribble.domain.repository.ShotRepository
import io.reactivex.Completable
import io.reactivex.Flowable
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.armcha.ribble.domain.interactor

import io.armcha.ribble.data.network.ApiConstants
import io.armcha.ribble.data.repository.ShotDataRepository
import io.armcha.ribble.di.scope.PerActivity
import io.armcha.ribble.domain.entity.Shot
import io.armcha.ribble.domain.repository.ShotRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.armcha.ribble.domain.interactor

import io.armcha.ribble.data.pref.Preferences
import io.armcha.ribble.di.scope.PerActivity
import io.armcha.ribble.domain.entity.Like
import io.armcha.ribble.domain.entity.User
Expand All @@ -13,12 +12,11 @@ import javax.inject.Inject
* Created by Chatikyan on 10.08.2017.
*/
@PerActivity
class UserInteractor @Inject constructor(private val userDataRepository: UserRepository,
private val preferences: Preferences) {
class UserInteractor @Inject constructor(private val userDataRepository: UserRepository) {

fun getUser(code: String): Flowable<User> {
return userDataRepository.getToken(code)
.doOnNext { preferences saveUserToken it.token }
.doOnNext { userDataRepository.saveToken(it.token) }
.flatMap { userDataRepository.getUser() }
.doOnNext { userDataRepository.logIn() }
}
Expand All @@ -28,7 +26,7 @@ class UserInteractor @Inject constructor(private val userDataRepository: UserRep
userDataRepository.clearLoginData()
}

fun clearCache(){
fun clearCache() {
userDataRepository.clearCache()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ interface UserRepository {
fun clearLoginData()

fun getToken(authCode: String):Flowable<TokenResponse>

fun saveToken(token:String?)
}

0 comments on commit e188ab3

Please sign in to comment.