Skip to content

Commit

Permalink
refactor: 토큰 리포지터리 변경된 함수로 값을 받아오도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
re4rk committed Oct 6, 2023
1 parent 49a2535 commit 5b2b5eb
Showing 1 changed file with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.festago.festago.data.repository
import com.festago.festago.data.datasource.TokenDataSource
import com.festago.festago.data.dto.OauthRequest
import com.festago.festago.data.service.TokenRetrofitService
import com.festago.festago.data.util.runCatchingWithErrorHandler
import com.festago.festago.data.util.onSuccessOrCatch
import com.festago.festago.data.util.runRetrofitWithErrorHandler
import com.festago.festago.repository.TokenRepository
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
Expand All @@ -18,23 +19,14 @@ class TokenDefaultRepository @Inject constructor(
tokenLocalDataSource.token = value
}

override suspend fun signIn(socialType: String, token: String): Result<Unit> {
tokenRetrofitService.getOauthToken(OauthRequest(socialType, token))
.runCatchingWithErrorHandler()
.getOrElse { error -> return Result.failure(error) }
.let {
tokenLocalDataSource.token = it.accessToken
return Result.success(Unit)
}
}
override suspend fun signIn(socialType: String, token: String): Result<Unit> =
runRetrofitWithErrorHandler {
tokenRetrofitService.getOauthToken(OauthRequest(socialType, token))
}.onSuccessOrCatch { tokenLocalDataSource.token = it.accessToken }

override fun refreshToken(token: String): Result<Unit> = runBlocking {
tokenRetrofitService.getOauthToken(OauthRequest("KAKAO", token))
.runCatchingWithErrorHandler()
.getOrElse { error -> return@runBlocking Result.failure(error) }
.let {
tokenLocalDataSource.token = it.accessToken
return@runBlocking Result.success(Unit)
}
runRetrofitWithErrorHandler {
tokenRetrofitService.getOauthToken(OauthRequest("KAKAO", token))
}.onSuccessOrCatch { tokenLocalDataSource.token = it.accessToken }
}
}

0 comments on commit 5b2b5eb

Please sign in to comment.