diff --git a/android/festago/data/src/main/java/com/festago/festago/data/di/singletonscope/DataSourceModule.kt b/android/festago/data/src/main/java/com/festago/festago/data/di/singletonscope/DataSourceModule.kt index 9f115eaed..b0acbb14c 100644 --- a/android/festago/data/src/main/java/com/festago/festago/data/di/singletonscope/DataSourceModule.kt +++ b/android/festago/data/src/main/java/com/festago/festago/data/di/singletonscope/DataSourceModule.kt @@ -2,6 +2,8 @@ package com.festago.festago.data.di.singletonscope import com.festago.festago.data.datasource.token.TokenDataSource import com.festago.festago.data.datasource.token.TokenLocalDataSource +import com.festago.festago.data.datasource.userinfo.UserInfoDataSource +import com.festago.festago.data.datasource.userinfo.UserInfoLocalDataSource import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -12,5 +14,8 @@ import dagger.hilt.components.SingletonComponent interface DataSourceModule { @Binds - fun bindsTokenDataSource(localDataSource: TokenLocalDataSource): TokenDataSource + fun bindsTokenDataSource(tokenDataSource: TokenLocalDataSource): TokenDataSource + + @Binds + fun bindsUserInfoDataSource(userInfoDataSource: UserInfoLocalDataSource): UserInfoDataSource } diff --git a/android/festago/data/src/main/java/com/festago/festago/data/dto/user/TokenResponse.kt b/android/festago/data/src/main/java/com/festago/festago/data/dto/user/TokenResponse.kt index ead579e20..b02033d36 100644 --- a/android/festago/data/src/main/java/com/festago/festago/data/dto/user/TokenResponse.kt +++ b/android/festago/data/src/main/java/com/festago/festago/data/dto/user/TokenResponse.kt @@ -1,7 +1,7 @@ package com.festago.festago.data.dto.user import com.festago.festago.data.model.TokenEntity -import com.festago.festago.domain.model.token.Token +import com.festago.festago.domain.model.user.Token import kotlinx.serialization.Serializable import java.time.LocalDateTime diff --git a/android/festago/data/src/main/java/com/festago/festago/data/model/TokenEntity.kt b/android/festago/data/src/main/java/com/festago/festago/data/model/TokenEntity.kt index ca9e6efe1..598f2e426 100644 --- a/android/festago/data/src/main/java/com/festago/festago/data/model/TokenEntity.kt +++ b/android/festago/data/src/main/java/com/festago/festago/data/model/TokenEntity.kt @@ -1,6 +1,6 @@ package com.festago.festago.data.model -import com.festago.festago.domain.model.token.Token +import com.festago.festago.domain.model.user.Token import java.time.LocalDateTime data class TokenEntity( diff --git a/android/festago/data/src/main/java/com/festago/festago/data/model/UserInfoEntity.kt b/android/festago/data/src/main/java/com/festago/festago/data/model/UserInfoEntity.kt index 263dc049a..f1cb00503 100644 --- a/android/festago/data/src/main/java/com/festago/festago/data/model/UserInfoEntity.kt +++ b/android/festago/data/src/main/java/com/festago/festago/data/model/UserInfoEntity.kt @@ -1,6 +1,13 @@ package com.festago.festago.data.model +import com.festago.festago.domain.model.user.UserInfo + data class UserInfoEntity( val nickname: String, val profileImageUrl: String, -) +) { + fun toDomain() = UserInfo( + nickname = nickname, + profileImageUrl = profileImageUrl, + ) +} diff --git a/android/festago/data/src/main/java/com/festago/festago/data/repository/DefaultUserRepository.kt b/android/festago/data/src/main/java/com/festago/festago/data/repository/DefaultUserRepository.kt index 0f3ad682c..6eee73cc8 100644 --- a/android/festago/data/src/main/java/com/festago/festago/data/repository/DefaultUserRepository.kt +++ b/android/festago/data/src/main/java/com/festago/festago/data/repository/DefaultUserRepository.kt @@ -4,12 +4,15 @@ import android.content.Context import android.content.SharedPreferences import com.festago.festago.common.kakao.KakaoAuthorization import com.festago.festago.data.datasource.token.TokenDataSource +import com.festago.festago.data.datasource.userinfo.UserInfoDataSource import com.festago.festago.data.dto.user.RefreshRequest import com.festago.festago.data.dto.user.SignInRequest +import com.festago.festago.data.model.UserInfoEntity import com.festago.festago.data.service.AuthRetrofitService import com.festago.festago.data.util.onSuccessOrCatch import com.festago.festago.data.util.runCatchingResponse -import com.festago.festago.domain.model.token.Token +import com.festago.festago.domain.model.user.Token +import com.festago.festago.domain.model.user.UserInfo import com.festago.festago.domain.repository.UserRepository import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject @@ -18,6 +21,7 @@ class DefaultUserRepository @Inject constructor( private val authRetrofitService: AuthRetrofitService, private val tokenDataSource: TokenDataSource, private val kakaoAuthorization: KakaoAuthorization, + private val userInfoDataSource: UserInfoDataSource, @ApplicationContext context: Context, ) : UserRepository { @@ -61,6 +65,8 @@ class DefaultUserRepository @Inject constructor( return runCatchingResponse { authRetrofitService.signIn(SignInRequest(SOCIAL_TYPE, idToken)) }.onSuccessOrCatch { signInResponse -> + userInfoDataSource.userInfo = + UserInfoEntity(signInResponse.nickname, signInResponse.profileImageUrl) tokenDataSource.accessToken = signInResponse.accessToken.toEntity() tokenDataSource.refreshToken = signInResponse.refreshToken.toEntity() } @@ -103,6 +109,11 @@ class DefaultUserRepository @Inject constructor( } } + override suspend fun getUserInfo(): Result { + return userInfoDataSource.userInfo?.toDomain()?.let { Result.success(it) } + ?: Result.failure(NullPointerException("User info is null")) + } + companion object { private const val SOCIAL_TYPE = "KAKAO" private const val AUTH_PREF = "auth_pref" diff --git a/android/festago/data/src/main/java/com/festago/festago/data/repository/FakeUserRepository.kt b/android/festago/data/src/main/java/com/festago/festago/data/repository/FakeUserRepository.kt index 7a13438e1..b3cb0c585 100644 --- a/android/festago/data/src/main/java/com/festago/festago/data/repository/FakeUserRepository.kt +++ b/android/festago/data/src/main/java/com/festago/festago/data/repository/FakeUserRepository.kt @@ -1,6 +1,7 @@ package com.festago.festago.data.repository -import com.festago.festago.domain.model.token.Token +import com.festago.festago.domain.model.user.Token +import com.festago.festago.domain.model.user.UserInfo import com.festago.festago.domain.repository.UserRepository import java.time.LocalDateTime import javax.inject.Inject @@ -38,4 +39,8 @@ class FakeUserRepository @Inject constructor() : UserRepository { override suspend fun deleteAccount(): Result { return Result.success(Unit) } + + override suspend fun getUserInfo(): Result { + return Result.success(UserInfo("", "")) + } } diff --git a/android/festago/domain/src/main/java/com/festago/festago/domain/model/token/Token.kt b/android/festago/domain/src/main/java/com/festago/festago/domain/model/user/Token.kt similarity index 78% rename from android/festago/domain/src/main/java/com/festago/festago/domain/model/token/Token.kt rename to android/festago/domain/src/main/java/com/festago/festago/domain/model/user/Token.kt index 16a5b4752..58869af3d 100644 --- a/android/festago/domain/src/main/java/com/festago/festago/domain/model/token/Token.kt +++ b/android/festago/domain/src/main/java/com/festago/festago/domain/model/user/Token.kt @@ -1,4 +1,4 @@ -package com.festago.festago.domain.model.token +package com.festago.festago.domain.model.user import java.time.LocalDateTime diff --git a/android/festago/domain/src/main/java/com/festago/festago/domain/model/user/UserInfo.kt b/android/festago/domain/src/main/java/com/festago/festago/domain/model/user/UserInfo.kt new file mode 100644 index 000000000..43b7227ac --- /dev/null +++ b/android/festago/domain/src/main/java/com/festago/festago/domain/model/user/UserInfo.kt @@ -0,0 +1,6 @@ +package com.festago.festago.domain.model.user + +data class UserInfo( + val nickname: String, + val profileImageUrl: String, +) diff --git a/android/festago/domain/src/main/java/com/festago/festago/domain/repository/UserRepository.kt b/android/festago/domain/src/main/java/com/festago/festago/domain/repository/UserRepository.kt index b7ac3430a..f2eef3405 100644 --- a/android/festago/domain/src/main/java/com/festago/festago/domain/repository/UserRepository.kt +++ b/android/festago/domain/src/main/java/com/festago/festago/domain/repository/UserRepository.kt @@ -1,6 +1,7 @@ package com.festago.festago.domain.repository -import com.festago.festago.domain.model.token.Token +import com.festago.festago.domain.model.user.Token +import com.festago.festago.domain.model.user.UserInfo interface UserRepository { suspend fun isSignRejected(): Boolean @@ -11,4 +12,5 @@ interface UserRepository { suspend fun signOut(): Result suspend fun deleteAccount(): Result suspend fun rejectSignIn() + suspend fun getUserInfo(): Result }