Skip to content

Commit

Permalink
[FEAT]#30: KakaoLogin idtoken을 서버에 보내요
Browse files Browse the repository at this point in the history
  • Loading branch information
flash159483 committed Jul 17, 2024
1 parent 68ffea7 commit 12147ff
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.bff.wespot.model.auth.request
data class KakaoAuthToken(
val accessToken: String,
val idToken: String?,
val socialType: String
val socialType: String = "KAKAO"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.bff.wespot.model.auth.response

data class AuthToken(
val accessToken: String,
val refreshToken: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bff.wespot.network.model.auth.request

import kotlinx.serialization.Serializable

@Serializable
data class KakaoAuthTokenDto(
val socialType: String,
val identityToken: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.bff.wespot.network.model.auth.response

import com.bff.wespot.model.auth.response.AuthToken
import kotlinx.serialization.Serializable

@Serializable
data class AuthTokenDto(
val accessToken: String,
val refreshToken: String,
) {
fun toAuthToken() = AuthToken(
accessToken = accessToken,
refreshToken = refreshToken,
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bff.wespot.network.model.auth
package com.bff.wespot.network.model.auth.response

import com.bff.wespot.model.auth.School
import com.bff.wespot.model.auth.response.School
import kotlinx.serialization.Serializable

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bff.wespot.network.model.auth
package com.bff.wespot.network.model.auth.response

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.bff.wespot.network.source.auth

import com.bff.wespot.network.model.auth.SchoolListDto
import com.bff.wespot.network.model.auth.request.KakaoAuthTokenDto
import com.bff.wespot.network.model.auth.response.AuthTokenDto
import com.bff.wespot.network.model.auth.response.SchoolListDto

interface AuthDataSource {
suspend fun getSchoolList(search: String): Result<SchoolListDto>
suspend fun sendKakaoToken(token: KakaoAuthTokenDto): Result<AuthTokenDto>
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.bff.wespot.network.source.auth

import com.bff.wespot.network.extensions.safeRequest
import com.bff.wespot.network.model.auth.SchoolListDto
import com.bff.wespot.network.model.auth.request.KakaoAuthTokenDto
import com.bff.wespot.network.model.auth.response.AuthTokenDto
import com.bff.wespot.network.model.auth.response.SchoolListDto
import io.ktor.client.HttpClient
import io.ktor.client.request.parameter
import io.ktor.client.request.setBody
import io.ktor.http.HttpMethod
import io.ktor.http.path
import javax.inject.Inject
Expand All @@ -19,4 +22,13 @@ class AuthDataSourceImpl @Inject constructor(
parameter("name", search)
}
}

override suspend fun sendKakaoToken(token: KakaoAuthTokenDto): Result<AuthTokenDto> =
httpClient.safeRequest {
url {
method = HttpMethod.Post
path("api/v1/auth/login")
}
setBody(token)
}
}
18 changes: 17 additions & 1 deletion data/src/main/kotlin/com/bff/wespot/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package com.bff.wespot.data.di

import com.bff.wespot.data.local.WeSpotDataStore
import com.bff.wespot.data.local.WeSpotDataStoreImpl
import com.bff.wespot.data.repository.DataStoreRepositoryImpl
import com.bff.wespot.data.repository.auth.AuthRepositoryImpl
import com.bff.wespot.data.repository.auth.KakaoLoginManagerImpl
import com.bff.wespot.domain.repository.message.MessageRepository
import com.bff.wespot.data.repository.message.MessageRepositoryImpl
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.repository.message.MessageRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -27,9 +31,21 @@ abstract class DataModule {
kakaoLoginManagerImpl: KakaoLoginManagerImpl
): KakaoLoginManager

@Binds
@Singleton
abstract fun bindsAuthRepository(
authRepositoryImpl: AuthRepositoryImpl
): AuthRepository

@Binds
@Singleton
abstract fun bindsWeSpotDataStore(
weSpotDataStoreImpl: WeSpotDataStoreImpl
): WeSpotDataStore

@Binds
@Singleton
abstract fun bindsDataStoreRepository(
dataStoreRepositoryImpl: DataStoreRepositoryImpl
): DataStoreRepository
}
10 changes: 10 additions & 0 deletions data/src/main/kotlin/com/bff/wespot/data/mapper/auth/AuthMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.bff.wespot.data.mapper.auth

import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.bff.wespot.network.model.auth.request.KakaoAuthTokenDto

internal fun KakaoAuthToken.toDto() =
KakaoAuthTokenDto(
socialType = socialType,
identityToken = idToken ?: "",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.bff.wespot.data.repository

import com.bff.wespot.data.local.WeSpotDataStore
import com.bff.wespot.domain.repository.DataStoreRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class DataStoreRepositoryImpl @Inject constructor(
private val dataStore: WeSpotDataStore
) : DataStoreRepository {
override suspend fun saveString(key: String, value: String) =
dataStore.saveString(key, value)

override fun getString(key: String): Flow<String> =
dataStore.getString(key)

override suspend fun saveBoolean(key: String, value: Boolean) =
dataStore.saveBoolean(key, value)

override fun getBoolean(key: String): Flow<Boolean> =
dataStore.getBoolean(key)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.bff.wespot.data.repository.auth

import android.content.Context
import com.bff.wespot.domain.repository.auth.KakaoLoginManager
import com.bff.wespot.model.auth.KakaoAuthToken
import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.bff.wespot.domain.repository.auth

import com.bff.wespot.model.auth.School
import com.bff.wespot.model.auth.request.KakaoAuthToken
import com.bff.wespot.model.auth.response.AuthToken
import com.bff.wespot.model.auth.response.School

interface AuthRepository {
suspend fun getSchoolList(search: String): Result<List<School>>
suspend fun sendKakaoToken(token: KakaoAuthToken): Result<AuthToken>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bff.wespot.domain.repository.auth

import com.bff.wespot.model.auth.KakaoAuthToken
import com.bff.wespot.model.auth.request.KakaoAuthToken

interface KakaoLoginManager {
suspend fun loginWithKakao(): KakaoAuthToken
Expand Down

0 comments on commit 12147ff

Please sign in to comment.