From e8a26067f2c98b064018eaff5609e15570523590 Mon Sep 17 00:00:00 2001 From: KwakEuiJin Date: Fri, 12 Jan 2024 22:11:30 +0900 Subject: [PATCH 1/2] [feat]: add login api --- .../hamyeonham/core/network/di/LoginModule.kt | 19 +++++++++++++++++ .../core/network/login/SocialLoginService.kt | 11 ++++++++++ .../network/login/model/SocialLoginRequest.kt | 10 +++++++++ .../login/model/SocialLoginResponse.kt | 21 +++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 core/network/src/main/java/com/hmh/hamyeonham/core/network/di/LoginModule.kt create mode 100644 core/network/src/main/java/com/hmh/hamyeonham/core/network/login/SocialLoginService.kt create mode 100644 core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginRequest.kt create mode 100644 core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginResponse.kt diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/di/LoginModule.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/di/LoginModule.kt new file mode 100644 index 000000000..9fc4f2dcb --- /dev/null +++ b/core/network/src/main/java/com/hmh/hamyeonham/core/network/di/LoginModule.kt @@ -0,0 +1,19 @@ +package com.hmh.hamyeonham.core.network.di + +import com.hmh.hamyeonham.common.qualifier.Unsecured +import com.hmh.hamyeonham.core.network.login.SocialLoginService +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import retrofit2.Retrofit +import retrofit2.create +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object LoginModule { + @Provides + @Singleton + fun provideLoginApi(@Unsecured retrofit: Retrofit): SocialLoginService = retrofit.create() +} diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/SocialLoginService.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/SocialLoginService.kt new file mode 100644 index 000000000..3e35e6610 --- /dev/null +++ b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/SocialLoginService.kt @@ -0,0 +1,11 @@ +package com.hmh.hamyeonham.core.network.login + +import com.hmh.hamyeonham.core.network.login.model.SocialLoginRequest +import com.hmh.hamyeonham.core.network.login.model.SocialLoginResponse +import com.hmh.hamyeonham.core.network.model.BaseResponse +import retrofit2.http.POST + +interface SocialLoginService { + @POST("api/v1/user/login") + suspend fun login(request: SocialLoginRequest): BaseResponse +} diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginRequest.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginRequest.kt new file mode 100644 index 000000000..bcab723e2 --- /dev/null +++ b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginRequest.kt @@ -0,0 +1,10 @@ +package com.hmh.hamyeonham.core.network.login.model + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class SocialLoginRequest( + @SerialName("socialPlatform") + val socialPlatform: String, +) diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginResponse.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginResponse.kt new file mode 100644 index 000000000..796df8458 --- /dev/null +++ b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginResponse.kt @@ -0,0 +1,21 @@ +package com.hmh.hamyeonham.core.network.login.model + + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class SocialLoginResponse( + @SerialName("token") + val token: Token? = null, + @SerialName("userId") + val userId: Int? = null +) { + @Serializable + data class Token( + @SerialName("accessToken") + val accessToken: String? = null, + @SerialName("refreshToken") + val refreshToken: String? = null + ) +} From edf72f08977ad30944bfa91de37730b68a906dfb Mon Sep 17 00:00:00 2001 From: KwakEuiJin Date: Fri, 12 Jan 2024 23:22:44 +0900 Subject: [PATCH 2/2] [feat]: add login logic --- app/build.gradle.kts | 2 + core/database/consumer-rules.pro | 0 core/designsystem/consumer-rules.pro | 0 core/designsystem/proguard-rules.pro | 21 ------ core/network/consumer-rules.pro | 0 core/network/proguard-rules.pro | 21 ------ .../hamyeonham/core/network/di/LoginModule.kt | 4 +- .../core/network/login/LoginService.kt | 16 +++++ .../core/network/login/SocialLoginService.kt | 11 --- ...{SocialLoginRequest.kt => LoginRequest.kt} | 2 +- ...ocialLoginResponse.kt => LoginResponse.kt} | 2 +- .../core/network/model/BaseResponse.kt | 7 ++ core/viewmodel/consumer-rules.pro | 0 core/viewmodel/main/consumer-rules.pro | 0 core/viewmodel/main/proguard-rules.pro | 21 ------ core/viewmodel/proguard-rules.pro | 21 ------ data/login/.gitignore | 1 + data/login/build.gradle.kts | 15 ++++ data/login/src/main/AndroidManifest.xml | 4 ++ .../login/DefaultLoginRepository.kt | 21 ++++++ .../hmh/hamyeonham/login/di/LoginModule.kt | 21 ++++++ .../hamyeonham/login/mapper/LoginMapper.kt | 14 ++++ data/onboarding/consumer-rules.pro | 0 data/onboarding/proguard-rules.pro | 21 ------ data/usagestats/consumer-rules.pro | 0 data/usagestats/proguard-rules.pro | 21 ------ data/userinfo/consumer-rules.pro | 0 data/userinfo/proguard-rules.pro | 21 ------ domain/challenge/consumer-rules.pro | 0 domain/challenge/proguard-rules.pro | 21 ------ domain/login/.gitignore | 1 + domain/login/build.gradle.kts | 9 +++ .../login}/consumer-rules.pro | 0 .../login}/proguard-rules.pro | 0 domain/login/src/main/AndroidManifest.xml | 4 ++ .../com/hmh/hamyeonham/login/model/Login.kt | 7 ++ .../login/repository/LoginRepository.kt | 7 ++ domain/usagestats/consumer-rules.pro | 0 domain/usagestats/proguard-rules.pro | 21 ------ domain/userinfo/consumer-rules.pro | 0 domain/userinfo/proguard-rules.pro | 21 ------ feature/challenge/consumer-rules.pro | 0 feature/challenge/proguard-rules.pro | 21 ------ feature/login/build.gradle.kts | 3 + feature/login/consumer-rules.pro | 0 feature/login/proguard-rules.pro | 21 ------ .../hamyeonham/feature/login/LoginActivity.kt | 13 ++-- .../feature/login/LoginViewModel.kt | 71 ++++++++----------- feature/main/consumer-rules.pro | 0 feature/main/proguard-rules.pro | 21 ------ feature/mypage/consumer-rules.pro | 0 feature/mypage/proguard-rules.pro | 21 ------ feature/onboarding/consumer-rules.pro | 0 feature/onboarding/proguard-rules.pro | 21 ------ settings.gradle.kts | 2 + 55 files changed, 174 insertions(+), 378 deletions(-) delete mode 100644 core/database/consumer-rules.pro delete mode 100644 core/designsystem/consumer-rules.pro delete mode 100644 core/designsystem/proguard-rules.pro delete mode 100644 core/network/consumer-rules.pro delete mode 100644 core/network/proguard-rules.pro create mode 100644 core/network/src/main/java/com/hmh/hamyeonham/core/network/login/LoginService.kt delete mode 100644 core/network/src/main/java/com/hmh/hamyeonham/core/network/login/SocialLoginService.kt rename core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/{SocialLoginRequest.kt => LoginRequest.kt} (87%) rename core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/{SocialLoginResponse.kt => LoginResponse.kt} (93%) delete mode 100644 core/viewmodel/consumer-rules.pro delete mode 100644 core/viewmodel/main/consumer-rules.pro delete mode 100644 core/viewmodel/main/proguard-rules.pro delete mode 100644 core/viewmodel/proguard-rules.pro create mode 100644 data/login/.gitignore create mode 100644 data/login/build.gradle.kts create mode 100644 data/login/src/main/AndroidManifest.xml create mode 100644 data/login/src/main/java/com/hmh/hamyeonham/login/DefaultLoginRepository.kt create mode 100644 data/login/src/main/java/com/hmh/hamyeonham/login/di/LoginModule.kt create mode 100644 data/login/src/main/java/com/hmh/hamyeonham/login/mapper/LoginMapper.kt delete mode 100644 data/onboarding/consumer-rules.pro delete mode 100644 data/onboarding/proguard-rules.pro delete mode 100644 data/usagestats/consumer-rules.pro delete mode 100644 data/usagestats/proguard-rules.pro delete mode 100644 data/userinfo/consumer-rules.pro delete mode 100644 data/userinfo/proguard-rules.pro delete mode 100644 domain/challenge/consumer-rules.pro delete mode 100644 domain/challenge/proguard-rules.pro create mode 100644 domain/login/.gitignore create mode 100644 domain/login/build.gradle.kts rename {core/common => domain/login}/consumer-rules.pro (100%) rename {core/database => domain/login}/proguard-rules.pro (100%) create mode 100644 domain/login/src/main/AndroidManifest.xml create mode 100644 domain/login/src/main/java/com/hmh/hamyeonham/login/model/Login.kt create mode 100644 domain/login/src/main/java/com/hmh/hamyeonham/login/repository/LoginRepository.kt delete mode 100644 domain/usagestats/consumer-rules.pro delete mode 100644 domain/usagestats/proguard-rules.pro delete mode 100644 domain/userinfo/consumer-rules.pro delete mode 100644 domain/userinfo/proguard-rules.pro delete mode 100644 feature/challenge/consumer-rules.pro delete mode 100644 feature/challenge/proguard-rules.pro delete mode 100644 feature/login/consumer-rules.pro delete mode 100644 feature/login/proguard-rules.pro delete mode 100644 feature/main/consumer-rules.pro delete mode 100644 feature/main/proguard-rules.pro delete mode 100644 feature/mypage/consumer-rules.pro delete mode 100644 feature/mypage/proguard-rules.pro delete mode 100644 feature/onboarding/consumer-rules.pro delete mode 100644 feature/onboarding/proguard-rules.pro diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4b292d98c..cefe9f87e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -66,10 +66,12 @@ dependencies { // Domain implementation(projects.domain.usagestats) implementation(projects.domain.userinfo) + implementation(projects.domain.login) // Data implementation(projects.data.usagestats) implementation(projects.data.userinfo) + implementation(projects.data.login) // Core implementation(projects.core.common) diff --git a/core/database/consumer-rules.pro b/core/database/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/designsystem/consumer-rules.pro b/core/designsystem/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/designsystem/proguard-rules.pro b/core/designsystem/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/core/designsystem/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/core/network/consumer-rules.pro b/core/network/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/network/proguard-rules.pro b/core/network/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/core/network/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/di/LoginModule.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/di/LoginModule.kt index 9fc4f2dcb..886eba716 100644 --- a/core/network/src/main/java/com/hmh/hamyeonham/core/network/di/LoginModule.kt +++ b/core/network/src/main/java/com/hmh/hamyeonham/core/network/di/LoginModule.kt @@ -1,7 +1,7 @@ package com.hmh.hamyeonham.core.network.di import com.hmh.hamyeonham.common.qualifier.Unsecured -import com.hmh.hamyeonham.core.network.login.SocialLoginService +import com.hmh.hamyeonham.core.network.login.LoginService import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -15,5 +15,5 @@ import javax.inject.Singleton object LoginModule { @Provides @Singleton - fun provideLoginApi(@Unsecured retrofit: Retrofit): SocialLoginService = retrofit.create() + fun provideLoginApi(@Unsecured retrofit: Retrofit): LoginService = retrofit.create() } diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/LoginService.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/LoginService.kt new file mode 100644 index 000000000..b84d148bf --- /dev/null +++ b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/LoginService.kt @@ -0,0 +1,16 @@ +package com.hmh.hamyeonham.core.network.login + +import com.hmh.hamyeonham.core.network.login.model.LoginRequest +import com.hmh.hamyeonham.core.network.login.model.LoginResponse +import com.hmh.hamyeonham.core.network.model.BaseResponse +import retrofit2.http.Body +import retrofit2.http.Header +import retrofit2.http.POST + +interface LoginService { + @POST("api/v1/user/login") + suspend fun login( + @Header("Authorization") accessToken: String, + @Body request: LoginRequest + ): BaseResponse +} diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/SocialLoginService.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/SocialLoginService.kt deleted file mode 100644 index 3e35e6610..000000000 --- a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/SocialLoginService.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.hmh.hamyeonham.core.network.login - -import com.hmh.hamyeonham.core.network.login.model.SocialLoginRequest -import com.hmh.hamyeonham.core.network.login.model.SocialLoginResponse -import com.hmh.hamyeonham.core.network.model.BaseResponse -import retrofit2.http.POST - -interface SocialLoginService { - @POST("api/v1/user/login") - suspend fun login(request: SocialLoginRequest): BaseResponse -} diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginRequest.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/LoginRequest.kt similarity index 87% rename from core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginRequest.kt rename to core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/LoginRequest.kt index bcab723e2..43c9d81c9 100644 --- a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginRequest.kt +++ b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/LoginRequest.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class SocialLoginRequest( +data class LoginRequest( @SerialName("socialPlatform") val socialPlatform: String, ) diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginResponse.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/LoginResponse.kt similarity index 93% rename from core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginResponse.kt rename to core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/LoginResponse.kt index 796df8458..904b8386b 100644 --- a/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/SocialLoginResponse.kt +++ b/core/network/src/main/java/com/hmh/hamyeonham/core/network/login/model/LoginResponse.kt @@ -5,7 +5,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class SocialLoginResponse( +data class LoginResponse( @SerialName("token") val token: Token? = null, @SerialName("userId") diff --git a/core/network/src/main/java/com/hmh/hamyeonham/core/network/model/BaseResponse.kt b/core/network/src/main/java/com/hmh/hamyeonham/core/network/model/BaseResponse.kt index ee5c1a941..3bb14b4eb 100644 --- a/core/network/src/main/java/com/hmh/hamyeonham/core/network/model/BaseResponse.kt +++ b/core/network/src/main/java/com/hmh/hamyeonham/core/network/model/BaseResponse.kt @@ -1,7 +1,14 @@ package com.hmh.hamyeonham.core.network.model +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable data class BaseResponse( + @SerialName("status") val status: Int, + @SerialName("message") val message: String, + @SerialName("data") val data: T ) diff --git a/core/viewmodel/consumer-rules.pro b/core/viewmodel/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/viewmodel/main/consumer-rules.pro b/core/viewmodel/main/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/core/viewmodel/main/proguard-rules.pro b/core/viewmodel/main/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/core/viewmodel/main/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/core/viewmodel/proguard-rules.pro b/core/viewmodel/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/core/viewmodel/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/data/login/.gitignore b/data/login/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/data/login/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/data/login/build.gradle.kts b/data/login/build.gradle.kts new file mode 100644 index 000000000..91e669ab4 --- /dev/null +++ b/data/login/build.gradle.kts @@ -0,0 +1,15 @@ +@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed +plugins { + hmh("feature") +} + +android { + namespace = "com.hmh.hamyeonham.data.login" +} + +dependencies { + implementation(projects.core.network) + implementation(projects.core.common) + + implementation(projects.domain.login) +} diff --git a/data/login/src/main/AndroidManifest.xml b/data/login/src/main/AndroidManifest.xml new file mode 100644 index 000000000..8bdb7e14b --- /dev/null +++ b/data/login/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/data/login/src/main/java/com/hmh/hamyeonham/login/DefaultLoginRepository.kt b/data/login/src/main/java/com/hmh/hamyeonham/login/DefaultLoginRepository.kt new file mode 100644 index 000000000..18fdd6b4e --- /dev/null +++ b/data/login/src/main/java/com/hmh/hamyeonham/login/DefaultLoginRepository.kt @@ -0,0 +1,21 @@ +package com.hmh.hamyeonham.login + +import com.hmh.hamyeonham.core.network.login.LoginService +import com.hmh.hamyeonham.core.network.login.model.LoginRequest +import com.hmh.hamyeonham.login.mapper.toLogin +import com.hmh.hamyeonham.login.model.Login +import com.hmh.hamyeonham.login.repository.LoginRepository +import javax.inject.Inject + +class DefaultLoginRepository @Inject constructor( + private val loginService: LoginService +) : LoginRepository { + + override suspend fun login(accessToken: String): Result { + val request = LoginRequest("KAKAO") + val bearerToken = "Bearer $accessToken" + return runCatching { + loginService.login(bearerToken, request).data.toLogin() + } + } +} diff --git a/data/login/src/main/java/com/hmh/hamyeonham/login/di/LoginModule.kt b/data/login/src/main/java/com/hmh/hamyeonham/login/di/LoginModule.kt new file mode 100644 index 000000000..81446c533 --- /dev/null +++ b/data/login/src/main/java/com/hmh/hamyeonham/login/di/LoginModule.kt @@ -0,0 +1,21 @@ +package com.hmh.hamyeonham.login.di + +import com.hmh.hamyeonham.login.DefaultLoginRepository +import com.hmh.hamyeonham.login.repository.LoginRepository +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object LoginModule { + @Module + @InstallIn(SingletonComponent::class) + interface Binder { + @Binds + @Singleton + fun provideUsageGoalsRepository(loginRepository: DefaultLoginRepository): LoginRepository + } +} diff --git a/data/login/src/main/java/com/hmh/hamyeonham/login/mapper/LoginMapper.kt b/data/login/src/main/java/com/hmh/hamyeonham/login/mapper/LoginMapper.kt new file mode 100644 index 000000000..b521c41cf --- /dev/null +++ b/data/login/src/main/java/com/hmh/hamyeonham/login/mapper/LoginMapper.kt @@ -0,0 +1,14 @@ +package com.hmh.hamyeonham.login.mapper + +import com.hmh.hamyeonham.core.network.login.model.LoginResponse +import com.hmh.hamyeonham.login.model.Login + +internal fun LoginResponse.toLogin(): Login { + return Login( + userId = userId ?: -1, + accessToken = token?.accessToken.orEmpty(), + refreshToken = token?.refreshToken.orEmpty(), + ) +} + + diff --git a/data/onboarding/consumer-rules.pro b/data/onboarding/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/data/onboarding/proguard-rules.pro b/data/onboarding/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/data/onboarding/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/data/usagestats/consumer-rules.pro b/data/usagestats/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/data/usagestats/proguard-rules.pro b/data/usagestats/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/data/usagestats/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/data/userinfo/consumer-rules.pro b/data/userinfo/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/data/userinfo/proguard-rules.pro b/data/userinfo/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/data/userinfo/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/domain/challenge/consumer-rules.pro b/domain/challenge/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/domain/challenge/proguard-rules.pro b/domain/challenge/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/domain/challenge/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/domain/login/.gitignore b/domain/login/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/domain/login/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/domain/login/build.gradle.kts b/domain/login/build.gradle.kts new file mode 100644 index 000000000..ed7223500 --- /dev/null +++ b/domain/login/build.gradle.kts @@ -0,0 +1,9 @@ +@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed +plugins { + `java-library` + kotlin("jvm") +} + +dependencies { + implementation(libs.javax.inject) +} diff --git a/core/common/consumer-rules.pro b/domain/login/consumer-rules.pro similarity index 100% rename from core/common/consumer-rules.pro rename to domain/login/consumer-rules.pro diff --git a/core/database/proguard-rules.pro b/domain/login/proguard-rules.pro similarity index 100% rename from core/database/proguard-rules.pro rename to domain/login/proguard-rules.pro diff --git a/domain/login/src/main/AndroidManifest.xml b/domain/login/src/main/AndroidManifest.xml new file mode 100644 index 000000000..8bdb7e14b --- /dev/null +++ b/domain/login/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/domain/login/src/main/java/com/hmh/hamyeonham/login/model/Login.kt b/domain/login/src/main/java/com/hmh/hamyeonham/login/model/Login.kt new file mode 100644 index 000000000..dfbc61c9f --- /dev/null +++ b/domain/login/src/main/java/com/hmh/hamyeonham/login/model/Login.kt @@ -0,0 +1,7 @@ +package com.hmh.hamyeonham.login.model + +data class Login( + val userId: Int, + val accessToken: String, + val refreshToken: String, +) diff --git a/domain/login/src/main/java/com/hmh/hamyeonham/login/repository/LoginRepository.kt b/domain/login/src/main/java/com/hmh/hamyeonham/login/repository/LoginRepository.kt new file mode 100644 index 000000000..92069819d --- /dev/null +++ b/domain/login/src/main/java/com/hmh/hamyeonham/login/repository/LoginRepository.kt @@ -0,0 +1,7 @@ +package com.hmh.hamyeonham.login.repository + +import com.hmh.hamyeonham.login.model.Login + +interface LoginRepository { + suspend fun login(accessToken: String): Result +} diff --git a/domain/usagestats/consumer-rules.pro b/domain/usagestats/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/domain/usagestats/proguard-rules.pro b/domain/usagestats/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/domain/usagestats/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/domain/userinfo/consumer-rules.pro b/domain/userinfo/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/domain/userinfo/proguard-rules.pro b/domain/userinfo/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/domain/userinfo/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/challenge/consumer-rules.pro b/feature/challenge/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/feature/challenge/proguard-rules.pro b/feature/challenge/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/feature/challenge/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/login/build.gradle.kts b/feature/login/build.gradle.kts index 003257920..3f458e28d 100644 --- a/feature/login/build.gradle.kts +++ b/feature/login/build.gradle.kts @@ -9,6 +9,9 @@ android { dependencies { + // Domain + implementation(projects.domain.login) + // Common implementation(projects.core.common) diff --git a/feature/login/consumer-rules.pro b/feature/login/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/feature/login/proguard-rules.pro b/feature/login/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/feature/login/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginActivity.kt b/feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginActivity.kt index da3e1a476..1d9277a39 100644 --- a/feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginActivity.kt +++ b/feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginActivity.kt @@ -1,11 +1,11 @@ package com.hmh.hamyeonham.feature.login import android.os.Bundle -import android.util.Log import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope +import com.hmh.hamyeonham.common.context.toast import com.hmh.hamyeonham.common.navigation.NavigationProvider import com.hmh.hamyeonham.common.view.viewBinding import com.hmh.hamyeonham.feature.login.databinding.ActivityLoginBinding @@ -35,13 +35,12 @@ class LoginActivity : AppCompatActivity() { } private fun handleKakaoLoginSuccess() { - viewModel.kakaoLoginState.flowWithLifecycle(lifecycle).onEach { state -> - if (state.isSuccessResult) { - viewModel.getKakaoUserNickname() - // 닉네임 출력 - Log.d("LoginActivity", "닉네임: ${state.kakaoNickname}") - moveToOnBoardingActivity() + viewModel.kakaoLoginEvent.flowWithLifecycle(lifecycle).onEach { state -> + when (state) { + is LoginEffect.LoginSuccess -> moveToOnBoardingActivity() + is LoginEffect.LoginFail -> toast("로그인에 실패했습니다.") } + moveToOnBoardingActivity() }.launchIn(lifecycleScope) } diff --git a/feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginViewModel.kt b/feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginViewModel.kt index cc94536c9..1a916201b 100644 --- a/feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginViewModel.kt +++ b/feature/login/src/main/java/com/hmh/hamyeonham/feature/login/LoginViewModel.kt @@ -1,32 +1,31 @@ package com.hmh.hamyeonham.feature.login import android.content.Context +import android.util.Log import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.hmh.hamyeonham.login.repository.LoginRepository import com.kakao.sdk.common.model.ClientError import com.kakao.sdk.common.model.ClientErrorCause import com.kakao.sdk.user.UserApiClient import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.asSharedFlow +import kotlinx.coroutines.launch import javax.inject.Inject -@HiltViewModel -class LoginViewModel @Inject constructor() : ViewModel() { - data class KakaoLoginState( - val isSuccessResult: Boolean = false, - val accessToken: String? = null, - val refreshToken: String? = null, - val kakaoNickname: String? = null, - ) +sealed interface LoginEffect { + data object LoginSuccess : LoginEffect + data object LoginFail : LoginEffect +} - private val _kakaoLoginState = MutableStateFlow(KakaoLoginState()) - val kakaoLoginState = _kakaoLoginState.asStateFlow() +@HiltViewModel +class LoginViewModel @Inject constructor( + private val loginRepository: LoginRepository +) : ViewModel() { - private fun updateState(transform: KakaoLoginState.() -> KakaoLoginState) { - val currentState = kakaoLoginState.value - val newState = currentState.transform() - _kakaoLoginState.value = newState - } + private val _kakaoLoginEvent = MutableSharedFlow() + val kakaoLoginEvent = _kakaoLoginEvent.asSharedFlow() fun loginWithKakaoApp(context: Context) { if (UserApiClient.instance.isKakaoTalkLoginAvailable(context)) { @@ -37,12 +36,13 @@ class LoginViewModel @Inject constructor() : ViewModel() { } loginWithKakaoAccount(context) } else if (token != null) { - updateState { - copy( - isSuccessResult = true, - accessToken = token.accessToken, - refreshToken = token.refreshToken, - ) + viewModelScope.launch { + loginRepository.login(token.accessToken).onSuccess { + _kakaoLoginEvent.emit(LoginEffect.LoginSuccess) + }.onFailure { + Log.e("LoginViewModel", "loginWithKakaoApp: $it") + _kakaoLoginEvent.emit(LoginEffect.LoginFail) + } } } } @@ -54,20 +54,14 @@ class LoginViewModel @Inject constructor() : ViewModel() { private fun loginWithKakaoAccount(context: Context) { UserApiClient.instance.loginWithKakaoAccount(context) { token, error -> if (error != null) { - updateState { - copy( - isSuccessResult = false, - accessToken = "", - refreshToken = "", - ) - } + // 닉네임 정보 얻기 실패 시 } else if (token != null) { - updateState { - copy( - isSuccessResult = true, - accessToken = token.accessToken, - refreshToken = token.refreshToken, - ) + viewModelScope.launch { + loginRepository.login(token.accessToken).onSuccess { + _kakaoLoginEvent.emit(LoginEffect.LoginSuccess) + }.onFailure { + _kakaoLoginEvent.emit(LoginEffect.LoginFail) + } } } } @@ -79,11 +73,6 @@ class LoginViewModel @Inject constructor() : ViewModel() { // 닉네임 정보 얻기 실패 시 } else if (user != null) { val kakaoNickname = user.kakaoAccount?.profile?.nickname - updateState { - copy( - kakaoNickname = kakaoNickname, - ) - } } } } diff --git a/feature/main/consumer-rules.pro b/feature/main/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/feature/main/proguard-rules.pro b/feature/main/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/feature/main/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/mypage/consumer-rules.pro b/feature/mypage/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/feature/mypage/proguard-rules.pro b/feature/mypage/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/feature/mypage/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/onboarding/consumer-rules.pro b/feature/onboarding/consumer-rules.pro deleted file mode 100644 index e69de29bb..000000000 diff --git a/feature/onboarding/proguard-rules.pro b/feature/onboarding/proguard-rules.pro deleted file mode 100644 index 481bb4348..000000000 --- a/feature/onboarding/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 05f3fad5c..199b798fa 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -39,3 +39,5 @@ include(":core:database") include(":core:designsystem") include(":core:viewmodel:main") include(":core:network") +include(":data:login") +include(":domain:login")