Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ dependencies {
projects.core.common,
projects.core.data.api,
projects.core.data.impl,
projects.core.datastore,
projects.core.datastore.api,
projects.core.datastore.impl,
projects.core.designsystem,
projects.core.model,
projects.core.network,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ninecraft.booket.core.data.api.repository

interface TokenManager {
suspend fun getAccessToken(): String
suspend fun getRefreshToken(): String
suspend fun setAccessToken(token: String)
suspend fun setRefreshToken(token: String)
suspend fun clearTokens()
}
2 changes: 1 addition & 1 deletion core/data/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
implementations(
projects.core.common,
projects.core.data.api,
projects.core.datastore,
projects.core.datastore.api,
projects.core.model,
projects.core.network,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.ninecraft.booket.core.data.impl.di

import com.ninecraft.booket.core.data.api.repository.AuthRepository
import com.ninecraft.booket.core.data.api.repository.TokenManager
import com.ninecraft.booket.core.data.impl.repository.DefaultAuthRepository
import com.ninecraft.booket.core.data.impl.repository.DefaultTokenManager
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -15,4 +17,8 @@ internal abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindAuthRepository(defaultAuthRepository: DefaultAuthRepository): AuthRepository

@Binds
@Singleton
abstract fun bindTokenManager(defaultTokenManager: DefaultTokenManager): TokenManager
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ninecraft.booket.core.data.impl.repository

import com.ninecraft.booket.core.data.api.repository.TokenManager
import com.ninecraft.booket.core.datastore.api.datasource.TokenPreferencesDataSource
import kotlinx.coroutines.flow.first
import javax.inject.Inject

internal class DefaultTokenManager @Inject constructor(
private val tokenPreferencesDataSource: TokenPreferencesDataSource,
) : TokenManager {
override suspend fun getAccessToken(): String = tokenPreferencesDataSource.accessToken.first()

override suspend fun getRefreshToken(): String = tokenPreferencesDataSource.refreshToken.first()

override suspend fun setAccessToken(token: String) {
tokenPreferencesDataSource.setRefreshToken(token)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

override suspend fun setRefreshToken(token: String) {
tokenPreferencesDataSource.setRefreshToken(token)
}

override suspend fun clearTokens() {
tokenPreferencesDataSource.clearTokens()
}
}
File renamed without changes.
11 changes: 11 additions & 0 deletions core/datastore/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
alias(libs.plugins.booket.android.library)
}

android {
namespace = "com.ninecraft.booket.core.datastore.api"
}

dependencies {
implementation(libs.kotlinx.coroutines.core)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninecraft.booket.core.datastore.datasource
package com.ninecraft.booket.core.datastore.api.datasource

import kotlinx.coroutines.flow.Flow

Expand Down
1 change: 1 addition & 0 deletions core/datastore/impl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

android {
namespace = "com.ninecraft.booket.core.datastore"
namespace = "com.ninecraft.booket.core.datastore.impl"

defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -15,6 +15,7 @@ android {

dependencies {
implementations(
projects.core.datastore.api,
libs.androidx.datastore.preferences,

libs.logger,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.ninecraft.booket.core.datastore
package com.ninecraft.booket.core.datastore.impl

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ninecraft.booket.core.datastore.datasource.DefaultTokenPreferencesDataSource
import com.ninecraft.booket.core.datastore.security.CryptoManager
import com.ninecraft.booket.core.datastore.impl.datasource.DefaultTokenPreferencesDataSource
import com.ninecraft.booket.core.datastore.impl.security.CryptoManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
Expand Down Expand Up @@ -37,7 +37,7 @@ class TokenPreferenceDataSourceTest {

dataStore = PreferenceDataStoreFactory.create(
scope = CoroutineScope(Dispatchers.IO + SupervisorJob()),
produceFile = { tempFile }
produceFile = { tempFile },
)

cryptoManager = CryptoManager()
Expand All @@ -50,7 +50,7 @@ class TokenPreferenceDataSourceTest {
}

@Test
fun tokenIsEncryptedWhenStored() = runTest {
fun 토큰은_암호화되어_저장된다() = runTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍 👍

// Given
val plainToken = "plain_access_token"
dataSource.setAccessToken(plainToken)
Expand All @@ -64,9 +64,8 @@ class TokenPreferenceDataSourceTest {
assertTrue(storedToken!!.isNotEmpty())
}


@Test
fun storedTokenIsDecryptedWhenRetrieved() = runTest {
fun 암호화된_토큰은_복호화되어_반환된다() = runTest {
// Given
val plainToken = "plain_access_token"
dataSource.setAccessToken(plainToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.ninecraft.booket.core.datastore.datasource
package com.ninecraft.booket.core.datastore.impl.datasource

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import com.ninecraft.booket.core.datastore.security.CryptoManager
import com.ninecraft.booket.core.datastore.util.handleIOException
import com.ninecraft.booket.core.datastore.api.datasource.TokenPreferencesDataSource
import com.ninecraft.booket.core.datastore.impl.security.CryptoManager
import com.ninecraft.booket.core.datastore.impl.util.handleIOException
import com.orhanobut.logger.Logger
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.ninecraft.booket.core.datastore.di
package com.ninecraft.booket.core.datastore.impl.di

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import com.ninecraft.booket.core.datastore.datasource.DefaultTokenPreferencesDataSource
import com.ninecraft.booket.core.datastore.datasource.TokenPreferencesDataSource
import com.ninecraft.booket.core.datastore.api.datasource.TokenPreferencesDataSource
import com.ninecraft.booket.core.datastore.impl.datasource.DefaultTokenPreferencesDataSource
import dagger.Binds
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -34,6 +34,6 @@ abstract class DataStoreBindModule {
@Binds
@Singleton
abstract fun bindTokenPreferencesDataSource(
tokenPreferencesDataSourceImpl: DefaultTokenPreferencesDataSource,
defaultTokenPreferencesDataSource: DefaultTokenPreferencesDataSource,
): TokenPreferencesDataSource
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninecraft.booket.core.datastore.security
package com.ninecraft.booket.core.datastore.impl.security

import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninecraft.booket.core.datastore.util
package com.ninecraft.booket.core.datastore.impl.util

import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.emptyPreferences
Expand Down
4 changes: 0 additions & 4 deletions core/datastore/src/main/AndroidManifest.xml

This file was deleted.

3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ include(
":core:common",
":core:data:api",
":core:data:impl",
":core:datastore",
":core:datastore:api",
":core:datastore:impl",
":core:designsystem",
":core:model",
":core:network",
Expand Down
Loading