From 1bb3ed2f12845326da9eec586b918b11561f68b6 Mon Sep 17 00:00:00 2001 From: Dongmin Date: Sun, 22 Sep 2024 03:50:44 +0900 Subject: [PATCH 1/2] [FEAT/#58] set login signUp --- .../kkkk/data/dataSource/AuthDataSource.kt | 7 +++++- .../data/dataSourceImpl/AuthDataSourceImpl.kt | 10 +++++--- .../kkkk/data/dto/request/AuthRequestDto.kt | 12 ++++++++++ .../data/repositoryImpl/AuthRepositoryImpl.kt | 23 ++++++++++++++----- .../java/com/kkkk/data/service/AuthService.kt | 12 +++++++--- .../kkkk/domain/repository/AuthRepository.kt | 4 ++++ .../onbarding/OnboardingActivity.kt | 8 ++++++- .../onbarding/OnboardingViewModel.kt | 16 ++++++++++--- 8 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 data/src/main/java/com/kkkk/data/dto/request/AuthRequestDto.kt diff --git a/data/src/main/java/com/kkkk/data/dataSource/AuthDataSource.kt b/data/src/main/java/com/kkkk/data/dataSource/AuthDataSource.kt index 51c0bef..bd4bd67 100644 --- a/data/src/main/java/com/kkkk/data/dataSource/AuthDataSource.kt +++ b/data/src/main/java/com/kkkk/data/dataSource/AuthDataSource.kt @@ -1,6 +1,7 @@ package com.kkkk.data.dataSource import com.kkkk.data.dto.BaseResponse +import com.kkkk.data.dto.request.AuthRequestDto import com.kkkk.data.dto.response.AuthTokenDto interface AuthDataSource { @@ -9,6 +10,10 @@ interface AuthDataSource { ): BaseResponse suspend fun postLogin( - deviceTag: String, + auth: AuthRequestDto, + ): BaseResponse + + suspend fun postSignUp( + auth: AuthRequestDto, ): BaseResponse } diff --git a/data/src/main/java/com/kkkk/data/dataSourceImpl/AuthDataSourceImpl.kt b/data/src/main/java/com/kkkk/data/dataSourceImpl/AuthDataSourceImpl.kt index ee32f98..fcee57a 100644 --- a/data/src/main/java/com/kkkk/data/dataSourceImpl/AuthDataSourceImpl.kt +++ b/data/src/main/java/com/kkkk/data/dataSourceImpl/AuthDataSourceImpl.kt @@ -2,6 +2,7 @@ package com.kkkk.data.dataSourceImpl import com.kkkk.data.dataSource.AuthDataSource import com.kkkk.data.dto.BaseResponse +import com.kkkk.data.dto.request.AuthRequestDto import com.kkkk.data.dto.response.AuthTokenDto import com.kkkk.data.service.AuthService import javax.inject.Inject @@ -12,10 +13,13 @@ constructor( private val authService: AuthService, ) : AuthDataSource { override suspend fun postReissueTokens( - authorization: String + authorization: String, ): BaseResponse = authService.postReissueTokens(authorization) override suspend fun postLogin( - deviceTag: String - ): BaseResponse = authService.postLogin(deviceTag) + auth: AuthRequestDto, + ): BaseResponse = authService.postLogin(auth) + + override suspend fun postSignUp(auth: AuthRequestDto): BaseResponse = + authService.postSignUp(auth) } diff --git a/data/src/main/java/com/kkkk/data/dto/request/AuthRequestDto.kt b/data/src/main/java/com/kkkk/data/dto/request/AuthRequestDto.kt new file mode 100644 index 0000000..e393a41 --- /dev/null +++ b/data/src/main/java/com/kkkk/data/dto/request/AuthRequestDto.kt @@ -0,0 +1,12 @@ +package com.kkkk.data.dto.request + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class AuthRequestDto( + @SerialName("deviceTag") + val deviceTag: String, + @SerialName("password") + val password: String = "" +) diff --git a/data/src/main/java/com/kkkk/data/repositoryImpl/AuthRepositoryImpl.kt b/data/src/main/java/com/kkkk/data/repositoryImpl/AuthRepositoryImpl.kt index 4c89e31..aaa9635 100644 --- a/data/src/main/java/com/kkkk/data/repositoryImpl/AuthRepositoryImpl.kt +++ b/data/src/main/java/com/kkkk/data/repositoryImpl/AuthRepositoryImpl.kt @@ -1,17 +1,16 @@ package com.kkkk.data.repositoryImpl import com.kkkk.data.dataSource.AuthDataSource +import com.kkkk.data.dto.request.AuthRequestDto import com.kkkk.domain.entity.response.AuthTokenModel import com.kkkk.domain.repository.AuthRepository import javax.inject.Inject -class AuthRepositoryImpl -@Inject -constructor( +class AuthRepositoryImpl @Inject constructor( private val authDataSource: AuthDataSource, ) : AuthRepository { override suspend fun reissueTokens( - authorization: String + authorization: String, ): Result = runCatching { authDataSource.postReissueTokens( authorization, @@ -19,8 +18,20 @@ constructor( } override suspend fun login( - deviceTag: String + deviceTag: String, ): Result = runCatching { - authDataSource.postLogin(deviceTag).data.toModel() + authDataSource.postLogin( + AuthRequestDto( + deviceTag = deviceTag + ) + ).data.toModel() + } + + override suspend fun signup(deviceTag: String): Result = runCatching { + authDataSource.postSignUp( + AuthRequestDto( + deviceTag = deviceTag + ) + ).data.toModel() } } diff --git a/data/src/main/java/com/kkkk/data/service/AuthService.kt b/data/src/main/java/com/kkkk/data/service/AuthService.kt index 11ea25e..493014b 100644 --- a/data/src/main/java/com/kkkk/data/service/AuthService.kt +++ b/data/src/main/java/com/kkkk/data/service/AuthService.kt @@ -1,6 +1,7 @@ package com.kkkk.data.service import com.kkkk.data.dto.BaseResponse +import com.kkkk.data.dto.request.AuthRequestDto import com.kkkk.data.dto.request.TokenRequestDto import com.kkkk.data.dto.response.AuthTokenDto import retrofit2.http.Body @@ -8,13 +9,18 @@ import retrofit2.http.Header import retrofit2.http.POST interface AuthService { - @POST("api/v1/reissue") + @POST("api/v1/auth/reissue") suspend fun postReissueTokens( @Header("Authorization") authorization: String ): BaseResponse - @POST("api/v1/login") + @POST("api/v1/auth/login") suspend fun postLogin( - @Header("Authorization") deviceTag: String, + @Body auth: AuthRequestDto, + ): BaseResponse + + @POST("api/v1/auth/register") + suspend fun postSignUp( + @Body auth: AuthRequestDto, ): BaseResponse } diff --git a/domain/src/main/kotlin/com/kkkk/domain/repository/AuthRepository.kt b/domain/src/main/kotlin/com/kkkk/domain/repository/AuthRepository.kt index 3ece755..f5abdd0 100644 --- a/domain/src/main/kotlin/com/kkkk/domain/repository/AuthRepository.kt +++ b/domain/src/main/kotlin/com/kkkk/domain/repository/AuthRepository.kt @@ -10,4 +10,8 @@ interface AuthRepository { suspend fun login( deviceTag: String ): Result + + suspend fun signup( + deviceTag: String + ): Result } diff --git a/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingActivity.kt b/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingActivity.kt index 4166d19..f29fa7e 100644 --- a/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingActivity.kt +++ b/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingActivity.kt @@ -1,7 +1,9 @@ package com.kkkk.presentation.onboarding.onbarding +import android.annotation.SuppressLint import android.os.Bundle import android.os.CountDownTimer +import android.provider.Settings import androidx.activity.viewModels import androidx.fragment.app.Fragment import androidx.fragment.app.commit @@ -56,7 +58,7 @@ class OnboardingActivity : BaseActivity(R.layout.acti override fun onFinish() { with(viewModel) { - setBpmLevel() + setBpmLevel(getDeviceTag()) setState(OnboardingState.END) } } @@ -76,6 +78,10 @@ class OnboardingActivity : BaseActivity(R.layout.acti } } + @SuppressLint("HardwareIds") + private fun getDeviceTag(): String = + Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) + companion object { private const val TIME = 60000L private const val INTERVAL = 1000L diff --git a/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingViewModel.kt b/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingViewModel.kt index dc48a47..56cc133 100644 --- a/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingViewModel.kt +++ b/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingViewModel.kt @@ -1,15 +1,20 @@ package com.kkkk.presentation.onboarding.onbarding import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.kkkk.domain.repository.AuthRepository import com.kkkk.domain.repository.UserRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch +import timber.log.Timber import javax.inject.Inject @HiltViewModel class OnboardingViewModel @Inject constructor( - private val userRepository: UserRepository + private val userRepository: UserRepository, + private val authRepository: AuthRepository, ) : ViewModel() { private val _state = MutableStateFlow(OnboardingState.START) val state: StateFlow = _state @@ -38,9 +43,14 @@ class OnboardingViewModel @Inject constructor( _state.value = newState } - fun setBpmLevel() { + fun setBpmLevel(deviceTag: String) { val bpm = _speed.value / (_stepCount.value / SPEED_CALC_INTERVAL) - userRepository.setBpm(bpm.toInt()) + + viewModelScope.launch { + authRepository.signup(deviceTag).onSuccess { + userRepository.setBpm(bpm.toInt()) + }.onFailure(Timber::e) + } } companion object { From 02552573ade5676f9912edfeb4f56c7561f9116b Mon Sep 17 00:00:00 2001 From: Dongmin Date: Sun, 22 Sep 2024 04:03:25 +0900 Subject: [PATCH 2/2] [FEAT/#58] connect navigation --- .../main/java/com/kkkk/data/dto/request/AuthRequestDto.kt | 2 +- .../java/com/kkkk/data/repositoryImpl/AuthRepositoryImpl.kt | 6 ++++-- .../kkkk/presentation/onboarding/splash/SplashActivity.kt | 4 ++-- .../kkkk/presentation/onboarding/splash/SplashViewModel.kt | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/data/src/main/java/com/kkkk/data/dto/request/AuthRequestDto.kt b/data/src/main/java/com/kkkk/data/dto/request/AuthRequestDto.kt index e393a41..832376b 100644 --- a/data/src/main/java/com/kkkk/data/dto/request/AuthRequestDto.kt +++ b/data/src/main/java/com/kkkk/data/dto/request/AuthRequestDto.kt @@ -8,5 +8,5 @@ data class AuthRequestDto( @SerialName("deviceTag") val deviceTag: String, @SerialName("password") - val password: String = "" + val password: String ) diff --git a/data/src/main/java/com/kkkk/data/repositoryImpl/AuthRepositoryImpl.kt b/data/src/main/java/com/kkkk/data/repositoryImpl/AuthRepositoryImpl.kt index aaa9635..359d856 100644 --- a/data/src/main/java/com/kkkk/data/repositoryImpl/AuthRepositoryImpl.kt +++ b/data/src/main/java/com/kkkk/data/repositoryImpl/AuthRepositoryImpl.kt @@ -22,7 +22,8 @@ class AuthRepositoryImpl @Inject constructor( ): Result = runCatching { authDataSource.postLogin( AuthRequestDto( - deviceTag = deviceTag + deviceTag = deviceTag, + password = "" ) ).data.toModel() } @@ -30,7 +31,8 @@ class AuthRepositoryImpl @Inject constructor( override suspend fun signup(deviceTag: String): Result = runCatching { authDataSource.postSignUp( AuthRequestDto( - deviceTag = deviceTag + deviceTag = deviceTag, + password = "" ) ).data.toModel() } diff --git a/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashActivity.kt b/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashActivity.kt index 99e99a7..909b49d 100644 --- a/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashActivity.kt +++ b/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashActivity.kt @@ -73,9 +73,9 @@ class SplashActivity : BaseActivity(R.layout.activity_spl private fun observeUserState() { viewModel.userState.flowWithLifecycle(lifecycle).onEach { isSuccess -> if (isSuccess) { - navigateToScreenClear() + navigateToScreenClear() } else { - toast(getString(R.string.error_msg)) + navigateToScreenClear() } }.launchIn(lifecycleScope) } diff --git a/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashViewModel.kt b/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashViewModel.kt index 9344453..e76ba8c 100644 --- a/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashViewModel.kt +++ b/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashViewModel.kt @@ -9,7 +9,6 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.launch -import timber.log.Timber import javax.inject.Inject @HiltViewModel @@ -39,7 +38,9 @@ class SplashViewModel @Inject constructor( userRepository.setTokens(response.accessToken, response.refreshToken) userRepository.setDeviceToken(deviceTag) _userState.emit(true) - }.onFailure(Timber::e) + }.onFailure { error -> // 401일 때 회원가입으로 이동 하도록 구현 필요 + _userState.emit(false) + } } }