Skip to content

Commit

Permalink
[FEAT]#30: Usecase로 로그인하면 저장해요
Browse files Browse the repository at this point in the history
  • Loading branch information
flash159483 committed Jul 17, 2024
1 parent 12147ff commit 4374fa7
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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<List<School>> =
authDataSource
.getSchoolList(search)
.map { it.schools.map(SchoolDto::toSchool) }

override suspend fun sendKakaoToken(token: KakaoAuthToken): Result<AuthToken> =
authDataSource
.sendKakaoToken(token.toDto())
.map { it.toAuthToken() }
}

This file was deleted.

1 change: 1 addition & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ dependencies {
implementation(project(":core:model"))

implementation(libs.java.inject)
implementation(libs.kotlin.coroutines)
}
Original file line number Diff line number Diff line change
@@ -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<String>
suspend fun saveBoolean(key: String, value: Boolean)
fun getBoolean(key: String): Flow<Boolean>
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.bff.wespot.domain.util

object DataStoreKey {
const val ACCESS_TOKEN = "access_token"
const val REFRESH_TOKEN = "refresh_token"
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down

0 comments on commit 4374fa7

Please sign in to comment.