diff --git a/core/model/src/main/kotlin/com/bff/wespot/model/auth/request/KakaoAuthToken.kt b/core/model/src/main/kotlin/com/bff/wespot/model/auth/request/KakaoAuthToken.kt index 99d2abc0..c80f5f0e 100644 --- a/core/model/src/main/kotlin/com/bff/wespot/model/auth/request/KakaoAuthToken.kt +++ b/core/model/src/main/kotlin/com/bff/wespot/model/auth/request/KakaoAuthToken.kt @@ -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" ) diff --git a/core/model/src/main/kotlin/com/bff/wespot/model/auth/response/AuthToken.kt b/core/model/src/main/kotlin/com/bff/wespot/model/auth/response/AuthToken.kt new file mode 100644 index 00000000..a7937b7f --- /dev/null +++ b/core/model/src/main/kotlin/com/bff/wespot/model/auth/response/AuthToken.kt @@ -0,0 +1,6 @@ +package com.bff.wespot.model.auth.response + +data class AuthToken( + val accessToken: String, + val refreshToken: String, +) \ No newline at end of file diff --git a/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/request/KakaoAuthTokenDto.kt b/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/request/KakaoAuthTokenDto.kt new file mode 100644 index 00000000..488f922a --- /dev/null +++ b/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/request/KakaoAuthTokenDto.kt @@ -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, +) \ No newline at end of file diff --git a/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/response/AuthTokenDto.kt b/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/response/AuthTokenDto.kt new file mode 100644 index 00000000..9d990f94 --- /dev/null +++ b/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/response/AuthTokenDto.kt @@ -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, + ) +} \ No newline at end of file diff --git a/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/SchoolDto.kt b/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/response/SchoolDto.kt similarity index 75% rename from core/network/src/main/kotlin/com/bff/wespot/network/model/auth/SchoolDto.kt rename to core/network/src/main/kotlin/com/bff/wespot/network/model/auth/response/SchoolDto.kt index 390284f5..b05c0248 100644 --- a/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/SchoolDto.kt +++ b/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/response/SchoolDto.kt @@ -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 diff --git a/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/SchoolListDto.kt b/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/response/SchoolListDto.kt similarity index 69% rename from core/network/src/main/kotlin/com/bff/wespot/network/model/auth/SchoolListDto.kt rename to core/network/src/main/kotlin/com/bff/wespot/network/model/auth/response/SchoolListDto.kt index 40bad0f2..22352466 100644 --- a/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/SchoolListDto.kt +++ b/core/network/src/main/kotlin/com/bff/wespot/network/model/auth/response/SchoolListDto.kt @@ -1,4 +1,4 @@ -package com.bff.wespot.network.model.auth +package com.bff.wespot.network.model.auth.response import kotlinx.serialization.Serializable diff --git a/core/network/src/main/kotlin/com/bff/wespot/network/source/auth/AuthDataSource.kt b/core/network/src/main/kotlin/com/bff/wespot/network/source/auth/AuthDataSource.kt index 6255fddd..70a98daa 100644 --- a/core/network/src/main/kotlin/com/bff/wespot/network/source/auth/AuthDataSource.kt +++ b/core/network/src/main/kotlin/com/bff/wespot/network/source/auth/AuthDataSource.kt @@ -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 + suspend fun sendKakaoToken(token: KakaoAuthTokenDto): Result } \ No newline at end of file diff --git a/core/network/src/main/kotlin/com/bff/wespot/network/source/auth/AuthDataSourceImpl.kt b/core/network/src/main/kotlin/com/bff/wespot/network/source/auth/AuthDataSourceImpl.kt index 236c5bc0..7ebbf123 100644 --- a/core/network/src/main/kotlin/com/bff/wespot/network/source/auth/AuthDataSourceImpl.kt +++ b/core/network/src/main/kotlin/com/bff/wespot/network/source/auth/AuthDataSourceImpl.kt @@ -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 @@ -19,4 +22,13 @@ class AuthDataSourceImpl @Inject constructor( parameter("name", search) } } + + override suspend fun sendKakaoToken(token: KakaoAuthTokenDto): Result = + httpClient.safeRequest { + url { + method = HttpMethod.Post + path("api/v1/auth/login") + } + setBody(token) + } } \ No newline at end of file diff --git a/data/src/main/kotlin/com/bff/wespot/data/di/DataModule.kt b/data/src/main/kotlin/com/bff/wespot/data/di/DataModule.kt index d20f7032..89065154 100644 --- a/data/src/main/kotlin/com/bff/wespot/data/di/DataModule.kt +++ b/data/src/main/kotlin/com/bff/wespot/data/di/DataModule.kt @@ -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 @@ -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 } diff --git a/data/src/main/kotlin/com/bff/wespot/data/mapper/auth/AuthMapper.kt b/data/src/main/kotlin/com/bff/wespot/data/mapper/auth/AuthMapper.kt new file mode 100644 index 00000000..dc29588e --- /dev/null +++ b/data/src/main/kotlin/com/bff/wespot/data/mapper/auth/AuthMapper.kt @@ -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 ?: "", + ) \ No newline at end of file diff --git a/data/src/main/kotlin/com/bff/wespot/data/repository/DataStoreRepositoryImpl.kt b/data/src/main/kotlin/com/bff/wespot/data/repository/DataStoreRepositoryImpl.kt new file mode 100644 index 00000000..23a42b88 --- /dev/null +++ b/data/src/main/kotlin/com/bff/wespot/data/repository/DataStoreRepositoryImpl.kt @@ -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 = + dataStore.getString(key) + + override suspend fun saveBoolean(key: String, value: Boolean) = + dataStore.saveBoolean(key, value) + + override fun getBoolean(key: String): Flow = + dataStore.getBoolean(key) +} \ No newline at end of file diff --git a/data/src/main/kotlin/com/bff/wespot/data/repository/auth/KakaoLoginManagerImpl.kt b/data/src/main/kotlin/com/bff/wespot/data/repository/auth/KakaoLoginManagerImpl.kt index 5426bd1d..b5452511 100644 --- a/data/src/main/kotlin/com/bff/wespot/data/repository/auth/KakaoLoginManagerImpl.kt +++ b/data/src/main/kotlin/com/bff/wespot/data/repository/auth/KakaoLoginManagerImpl.kt @@ -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 diff --git a/domain/src/main/kotlin/com/bff/wespot/domain/repository/auth/AuthRepository.kt b/domain/src/main/kotlin/com/bff/wespot/domain/repository/auth/AuthRepository.kt index 84ce1670..bf91719b 100644 --- a/domain/src/main/kotlin/com/bff/wespot/domain/repository/auth/AuthRepository.kt +++ b/domain/src/main/kotlin/com/bff/wespot/domain/repository/auth/AuthRepository.kt @@ -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> + suspend fun sendKakaoToken(token: KakaoAuthToken): Result } diff --git a/domain/src/main/kotlin/com/bff/wespot/domain/repository/auth/KakaoLoginManager.kt b/domain/src/main/kotlin/com/bff/wespot/domain/repository/auth/KakaoLoginManager.kt index 547443ec..4e38a89f 100644 --- a/domain/src/main/kotlin/com/bff/wespot/domain/repository/auth/KakaoLoginManager.kt +++ b/domain/src/main/kotlin/com/bff/wespot/domain/repository/auth/KakaoLoginManager.kt @@ -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