From ca32c5bc435e47207ec5cee20daf10dd4aa9adc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=ED=98=84?= Date: Mon, 18 Sep 2023 15:49:36 +0900 Subject: [PATCH 1/6] =?UTF-8?q?:sparkles:=20::=20Role=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/msg/data/local/datasource/LocalDataSource.kt | 3 +++ .../com/msg/data/local/datasource/LocalDataSourceImpl.kt | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/data/src/main/java/com/msg/data/local/datasource/LocalDataSource.kt b/data/src/main/java/com/msg/data/local/datasource/LocalDataSource.kt index 33a9b22f..b441a932 100644 --- a/data/src/main/java/com/msg/data/local/datasource/LocalDataSource.kt +++ b/data/src/main/java/com/msg/data/local/datasource/LocalDataSource.kt @@ -9,10 +9,13 @@ interface LocalDataSource { expiresAt: String ) + suspend fun saveRole(role: String) + fun getAccessToken(): Flow fun getRefreshToken(): Flow fun getExpiresAt(): Flow + fun getRole(): Flow } \ No newline at end of file diff --git a/data/src/main/java/com/msg/data/local/datasource/LocalDataSourceImpl.kt b/data/src/main/java/com/msg/data/local/datasource/LocalDataSourceImpl.kt index dc59f174..6477df88 100644 --- a/data/src/main/java/com/msg/data/local/datasource/LocalDataSourceImpl.kt +++ b/data/src/main/java/com/msg/data/local/datasource/LocalDataSourceImpl.kt @@ -20,6 +20,7 @@ class LocalDataSourceImpl @Inject constructor( private val ACCESS_TOKEN = stringPreferencesKey("access_token") private val REFRESH_TOKEN = stringPreferencesKey("refresh_token") private val EXPIRES_AT = stringPreferencesKey("expires_at") + private val ROLE = stringPreferencesKey("role") } override suspend fun saveToken(accessToken: String, refreshToken: String, expiresAt: String) { @@ -30,9 +31,17 @@ class LocalDataSourceImpl @Inject constructor( } } + override suspend fun saveRole(role: String) { + context.dataStore.edit { + it[ROLE] = role + } + } + override fun getAccessToken(): Flow = context.dataStore.data.map { it[ACCESS_TOKEN] ?: "" } override fun getRefreshToken(): Flow = context.dataStore.data.map { it[REFRESH_TOKEN] ?: "" } override fun getExpiresAt(): Flow = context.dataStore.data.map { it[EXPIRES_AT] ?: "" } + + override fun getRole(): Flow = context.dataStore.data.map { it[ROLE] ?: "" } } \ No newline at end of file From 71a4cdc531ddff283cfebf9fd3adec5e9bd0d738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=ED=98=84?= Date: Mon, 18 Sep 2023 15:50:08 +0900 Subject: [PATCH 2/6] =?UTF-8?q?:sparkles:=20::=20=EC=9E=AC=EB=B0=9C?= =?UTF-8?q?=EA=B8=89=20=EC=84=B1=EA=B3=B5=EC=8B=9C=20role=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/src/main/java/com/msg/data/remote/util/AuthInterceptor.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/data/src/main/java/com/msg/data/remote/util/AuthInterceptor.kt b/data/src/main/java/com/msg/data/remote/util/AuthInterceptor.kt index f0ddfab1..fbed3342 100644 --- a/data/src/main/java/com/msg/data/remote/util/AuthInterceptor.kt +++ b/data/src/main/java/com/msg/data/remote/util/AuthInterceptor.kt @@ -60,6 +60,7 @@ class AuthInterceptor @Inject constructor( refreshToken = token["refresh_token"].asString, expiresAt = token["expires_at"].asString ) + localDataSource.saveRole(token["role"].asString) } } else throw TokenExpiredException() } From 27c376e1e56979aaf9e1a540386781f1c16550b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=ED=98=84?= Date: Mon, 18 Sep 2023 15:56:30 +0900 Subject: [PATCH 3/6] =?UTF-8?q?:recycle:=20::=20api=20=ED=82=A4=20?= =?UTF-8?q?=EA=B0=92=EC=97=90=20=EB=A7=9E=EC=B6=B0=EC=84=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/msg/data/local/datasource/LocalDataSource.kt | 2 +- .../com/msg/data/local/datasource/LocalDataSourceImpl.kt | 6 +++--- .../main/java/com/msg/data/remote/util/AuthInterceptor.kt | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/data/src/main/java/com/msg/data/local/datasource/LocalDataSource.kt b/data/src/main/java/com/msg/data/local/datasource/LocalDataSource.kt index b441a932..c53fe50a 100644 --- a/data/src/main/java/com/msg/data/local/datasource/LocalDataSource.kt +++ b/data/src/main/java/com/msg/data/local/datasource/LocalDataSource.kt @@ -9,7 +9,7 @@ interface LocalDataSource { expiresAt: String ) - suspend fun saveRole(role: String) + suspend fun saveRole(roles: String) fun getAccessToken(): Flow diff --git a/data/src/main/java/com/msg/data/local/datasource/LocalDataSourceImpl.kt b/data/src/main/java/com/msg/data/local/datasource/LocalDataSourceImpl.kt index 6477df88..38f4fc93 100644 --- a/data/src/main/java/com/msg/data/local/datasource/LocalDataSourceImpl.kt +++ b/data/src/main/java/com/msg/data/local/datasource/LocalDataSourceImpl.kt @@ -20,7 +20,7 @@ class LocalDataSourceImpl @Inject constructor( private val ACCESS_TOKEN = stringPreferencesKey("access_token") private val REFRESH_TOKEN = stringPreferencesKey("refresh_token") private val EXPIRES_AT = stringPreferencesKey("expires_at") - private val ROLE = stringPreferencesKey("role") + private val ROLE = stringPreferencesKey("roles") } override suspend fun saveToken(accessToken: String, refreshToken: String, expiresAt: String) { @@ -31,9 +31,9 @@ class LocalDataSourceImpl @Inject constructor( } } - override suspend fun saveRole(role: String) { + override suspend fun saveRole(roles: String) { context.dataStore.edit { - it[ROLE] = role + it[ROLE] = roles } } diff --git a/data/src/main/java/com/msg/data/remote/util/AuthInterceptor.kt b/data/src/main/java/com/msg/data/remote/util/AuthInterceptor.kt index fbed3342..b797fcc1 100644 --- a/data/src/main/java/com/msg/data/remote/util/AuthInterceptor.kt +++ b/data/src/main/java/com/msg/data/remote/util/AuthInterceptor.kt @@ -56,11 +56,11 @@ class AuthInterceptor @Inject constructor( val token = JsonParser.parseString(response.body!!.string()) as JsonObject runBlocking { localDataSource.saveToken( - accessToken = token["access_token"].asString, - refreshToken = token["refresh_token"].asString, - expiresAt = token["expires_at"].asString + accessToken = token["accessToken"].asString, + refreshToken = token["refreshToken"].asString, + expiresAt = token["expiresAt"].asString ) - localDataSource.saveRole(token["role"].asString) + localDataSource.saveRole(token["roles"].asString) } } else throw TokenExpiredException() } From 1c028f432327e5ce814817d065af5bde0fb49751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=ED=98=84?= Date: Mon, 18 Sep 2023 16:01:50 +0900 Subject: [PATCH 4/6] =?UTF-8?q?:sparkles:=20::=20domain=EC=97=90=EC=84=9C?= =?UTF-8?q?=EB=8F=84=20=EC=93=B8=20=EC=88=98=20=EC=9E=88=EA=B2=8C=20reposi?= =?UTF-8?q?tory=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/msg/data/repository/AuthRepositoryImpl.kt | 2 ++ .../src/main/java/com/msg/domain/repository/AuthRepository.kt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/data/src/main/java/com/msg/data/repository/AuthRepositoryImpl.kt b/data/src/main/java/com/msg/data/repository/AuthRepositoryImpl.kt index bf8626b1..265ab678 100644 --- a/data/src/main/java/com/msg/data/repository/AuthRepositoryImpl.kt +++ b/data/src/main/java/com/msg/data/repository/AuthRepositoryImpl.kt @@ -25,4 +25,6 @@ class AuthRepositoryImpl @Inject constructor( refreshToken, expiresAt ) + + override suspend fun saveRole(roles: String) = localDataSource.saveRole(roles) } \ No newline at end of file diff --git a/domain/src/main/java/com/msg/domain/repository/AuthRepository.kt b/domain/src/main/java/com/msg/domain/repository/AuthRepository.kt index 16d9a748..201b1667 100644 --- a/domain/src/main/java/com/msg/domain/repository/AuthRepository.kt +++ b/domain/src/main/java/com/msg/domain/repository/AuthRepository.kt @@ -13,4 +13,6 @@ interface AuthRepository { refreshToken: String, expiresAt: String ) + + suspend fun saveRole(roles: String) } \ No newline at end of file From 0b8a9a965815e71fee68df3c4ef08a38dd7ca899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=ED=98=84?= Date: Mon, 18 Sep 2023 16:02:00 +0900 Subject: [PATCH 5/6] =?UTF-8?q?:sparkles:=20::=20domain=EC=97=90=EC=84=9C?= =?UTF-8?q?=EB=8F=84=20=EC=93=B8=20=EC=88=98=20=EC=9E=88=EA=B2=8C=20usecas?= =?UTF-8?q?e=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/msg/domain/usecase/auth/SaveRoleUseCase.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 domain/src/main/java/com/msg/domain/usecase/auth/SaveRoleUseCase.kt diff --git a/domain/src/main/java/com/msg/domain/usecase/auth/SaveRoleUseCase.kt b/domain/src/main/java/com/msg/domain/usecase/auth/SaveRoleUseCase.kt new file mode 100644 index 00000000..f82c7aaf --- /dev/null +++ b/domain/src/main/java/com/msg/domain/usecase/auth/SaveRoleUseCase.kt @@ -0,0 +1,10 @@ +package com.msg.domain.usecase.auth + +import com.msg.domain.repository.AuthRepository +import javax.inject.Inject + +class SaveRoleUseCase @Inject constructor( + private val authRepository: AuthRepository +) { + suspend operator fun invoke(roles: String) = kotlin.runCatching { authRepository.saveRole(roles) } +} \ No newline at end of file From 0dd454e2c026c8c0aa915ba5a2ea56069fccb5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=ED=98=84?= Date: Tue, 19 Sep 2023 08:15:48 +0900 Subject: [PATCH 6/6] =?UTF-8?q?:sparkles:=20::=20LoginViewModel=EC=97=90?= =?UTF-8?q?=EC=84=9C=20saveRoleUseCase=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/msg/presentation/viewmodel/LoginViewModel.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/presentation/src/main/java/com/msg/presentation/viewmodel/LoginViewModel.kt b/presentation/src/main/java/com/msg/presentation/viewmodel/LoginViewModel.kt index 60e11803..454a8043 100644 --- a/presentation/src/main/java/com/msg/presentation/viewmodel/LoginViewModel.kt +++ b/presentation/src/main/java/com/msg/presentation/viewmodel/LoginViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope import com.msg.domain.model.auth.LoginRequestModel import com.msg.domain.model.auth.LoginResponseModel import com.msg.domain.usecase.auth.LoginUseCase +import com.msg.domain.usecase.auth.SaveRoleUseCase import com.msg.domain.usecase.auth.SaveTokenUseCase import com.msg.presentation.exception.exceptionHandling import com.msg.presentation.viewmodel.util.Event @@ -15,7 +16,8 @@ import javax.inject.Inject class LoginViewModel @Inject constructor( private val loginUseCase: LoginUseCase, - private val saveTokenUseCase: SaveTokenUseCase + private val saveTokenUseCase: SaveTokenUseCase, + private val saveRoleUseCase: SaveRoleUseCase ) : ViewModel() { private val _loginState = MutableStateFlow>(Event.Loading) @@ -30,6 +32,7 @@ class LoginViewModel @Inject constructor( refreshToken = it.refreshToken, expiresAt = it.expiresAt ) + saveRoleUseCase(it.roles.toString()) } .onFailure { it.exceptionHandling(