diff --git a/data/src/main/kotlin/com/bff/wespot/data/repository/auth/AuthRepositoryImpl.kt b/data/src/main/kotlin/com/bff/wespot/data/repository/auth/AuthRepositoryImpl.kt new file mode 100644 index 00000000..8cb0ac36 --- /dev/null +++ b/data/src/main/kotlin/com/bff/wespot/data/repository/auth/AuthRepositoryImpl.kt @@ -0,0 +1,24 @@ +package com.bff.wespot.data.repository.auth + +import com.bff.wespot.data.mapper.auth.toDto +import com.bff.wespot.domain.repository.auth.AuthRepository +import com.bff.wespot.model.auth.request.KakaoAuthToken +import com.bff.wespot.model.auth.response.AuthToken +import com.bff.wespot.model.auth.response.School +import com.bff.wespot.network.model.auth.response.SchoolDto +import com.bff.wespot.network.source.auth.AuthDataSource +import javax.inject.Inject + +class AuthRepositoryImpl @Inject constructor( + private val authDataSource: AuthDataSource +) : AuthRepository { + override suspend fun getSchoolList(search: String): Result> = + authDataSource + .getSchoolList(search) + .map { it.schools.map(SchoolDto::toSchool) } + + override suspend fun sendKakaoToken(token: KakaoAuthToken): Result = + authDataSource + .sendKakaoToken(token.toDto()) + .map { it.toAuthToken() } +} \ No newline at end of file diff --git a/data/src/main/kotlin/com/bff/wespot/data/repository/message/AuthRepositoryImpl.kt b/data/src/main/kotlin/com/bff/wespot/data/repository/message/AuthRepositoryImpl.kt deleted file mode 100644 index 5136983f..00000000 --- a/data/src/main/kotlin/com/bff/wespot/data/repository/message/AuthRepositoryImpl.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.bff.wespot.data.repository.message - -import com.bff.wespot.domain.repository.auth.AuthRepository -import com.bff.wespot.model.auth.School -import com.bff.wespot.network.model.auth.SchoolDto -import com.bff.wespot.network.source.auth.AuthDataSource -import javax.inject.Inject - -class AuthRepositoryImpl @Inject constructor( - private val authDataSource: AuthDataSource -) : AuthRepository { - override suspend fun getSchoolList(search: String): Result> = - authDataSource - .getSchoolList(search) - .map { it.schools.map(SchoolDto::toSchool) } - -} \ No newline at end of file diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index f0841e34..eb9569bb 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -10,4 +10,5 @@ dependencies { implementation(project(":core:model")) implementation(libs.java.inject) + implementation(libs.kotlin.coroutines) } diff --git a/domain/src/main/kotlin/com/bff/wespot/domain/repository/DataStoreRepository.kt b/domain/src/main/kotlin/com/bff/wespot/domain/repository/DataStoreRepository.kt new file mode 100644 index 00000000..6b2864bb --- /dev/null +++ b/domain/src/main/kotlin/com/bff/wespot/domain/repository/DataStoreRepository.kt @@ -0,0 +1,10 @@ +package com.bff.wespot.domain.repository + +import kotlinx.coroutines.flow.Flow + +interface DataStoreRepository { + suspend fun saveString(key: String, value: String) + fun getString(key: String): Flow + suspend fun saveBoolean(key: String, value: Boolean) + fun getBoolean(key: String): Flow +} \ No newline at end of file diff --git a/domain/src/main/kotlin/com/bff/wespot/domain/usecase/KakaoLoginUseCase.kt b/domain/src/main/kotlin/com/bff/wespot/domain/usecase/KakaoLoginUseCase.kt index a810958a..5d578961 100644 --- a/domain/src/main/kotlin/com/bff/wespot/domain/usecase/KakaoLoginUseCase.kt +++ b/domain/src/main/kotlin/com/bff/wespot/domain/usecase/KakaoLoginUseCase.kt @@ -1,14 +1,26 @@ package com.bff.wespot.domain.usecase +import com.bff.wespot.domain.repository.DataStoreRepository +import com.bff.wespot.domain.repository.auth.AuthRepository import com.bff.wespot.domain.repository.auth.KakaoLoginManager +import com.bff.wespot.domain.util.DataStoreKey import javax.inject.Inject +import javax.xml.crypto.Data class KakaoLoginUseCase @Inject constructor( val kakaoLoginManager: KakaoLoginManager, + val authRepository: AuthRepository, + val dataStoreRepository: DataStoreRepository ) { - // 나중에 authrepository랑 연결될 예정 suspend inline fun invoke() { val result = kakaoLoginManager.loginWithKakao() - println("token $result") + authRepository.sendKakaoToken(result) + .onSuccess { + dataStoreRepository.saveString(DataStoreKey.ACCESS_TOKEN, it.accessToken) + dataStoreRepository.saveString(DataStoreKey.REFRESH_TOKEN, it.refreshToken) + } + .onFailure { + throw(it) + } } } diff --git a/domain/src/main/kotlin/com/bff/wespot/domain/util/DataStoreKey.kt b/domain/src/main/kotlin/com/bff/wespot/domain/util/DataStoreKey.kt new file mode 100644 index 00000000..4f979a70 --- /dev/null +++ b/domain/src/main/kotlin/com/bff/wespot/domain/util/DataStoreKey.kt @@ -0,0 +1,6 @@ +package com.bff.wespot.domain.util + +object DataStoreKey { + const val ACCESS_TOKEN = "access_token" + const val REFRESH_TOKEN = "refresh_token" +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4d3321a3..f35e4e78 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,6 +13,7 @@ core-ktx = "1.13.1" ksp = "2.0.0-1.0.22" ktlint = "12.1.1" detekt = "1.23.6" +kotlinx-coroutines = "1.7.1" java-inject = "1" lifecycle-runtime-ktx = "2.8.2" @@ -49,6 +50,7 @@ kotlin-gradle = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", kotlin-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" } kotlinx-collections-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "kotlinx-collections-immutable" } detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } +kotlin-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" } java-inject = { module = "javax.inject:javax.inject", version.ref = "java-inject" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }