From 5b2b5ebae3d5a87730d82c81f14f8e38db58d839 Mon Sep 17 00:00:00 2001 From: re4rk <37167652+re4rk@users.noreply.github.com> Date: Fri, 6 Oct 2023 20:50:23 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=86=A0=ED=81=B0=20=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=EC=A7=80=ED=84=B0=EB=A6=AC=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EB=90=9C=20=ED=95=A8=EC=88=98=EB=A1=9C=20=EA=B0=92=EC=9D=84=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84=EC=98=A4=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repository/TokenDefaultRepository.kt | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/android/festago/app/src/main/java/com/festago/festago/data/repository/TokenDefaultRepository.kt b/android/festago/app/src/main/java/com/festago/festago/data/repository/TokenDefaultRepository.kt index 1f3d083b5..dc42ab4e5 100644 --- a/android/festago/app/src/main/java/com/festago/festago/data/repository/TokenDefaultRepository.kt +++ b/android/festago/app/src/main/java/com/festago/festago/data/repository/TokenDefaultRepository.kt @@ -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 @@ -18,23 +19,14 @@ class TokenDefaultRepository @Inject constructor( tokenLocalDataSource.token = value } - override suspend fun signIn(socialType: String, token: String): Result { - 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 = + runRetrofitWithErrorHandler { + tokenRetrofitService.getOauthToken(OauthRequest(socialType, token)) + }.onSuccessOrCatch { tokenLocalDataSource.token = it.accessToken } override fun refreshToken(token: String): Result = 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 } } }