Skip to content

Commit

Permalink
refactor/#78 : 코드 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwon12 committed Feb 19, 2025
1 parent 1dec61a commit d5d9768
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import com.yapp.core.data.local.SecurityPreferences
import com.yapp.core.data.remote.api.LoginApi
import com.yapp.core.data.remote.model.request.LoginRequest
import com.yapp.dataapi.LoginRepository
import timber.log.Timber
import javax.inject.Inject

internal class LoginRepositoryImpl @Inject constructor(
private val loginApi: LoginApi,
private val securityPreferences: SecurityPreferences,
) : LoginRepository {
override suspend fun login(email: String, password: String){
override suspend fun login(email: String, password: String) {
val response = loginApi.login(LoginRequest(email = email, password = password))
response.let {
securityPreferences.setAccessToken(it.accessToken)
securityPreferences.setRefreshToken(it.refreshToken)
try {
securityPreferences.setAccessToken(response.accessToken)
securityPreferences.setRefreshToken(response.refreshToken)
} catch (e: Exception) {
Timber.e("토근 저장 실패")
}
}
}
14 changes: 14 additions & 0 deletions core/ui/src/main/java/com/yapp/core/ui/constant/Url.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
package com.yapp.core.ui.constant

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.widget.Toast

object Url {
const val TERMS = "https://yapp-workspace.notion.site/48f4eb2ffdd94740979e8a3b37ca260d"
const val PRIVACY_POLICY = "https://yapp-workspace.notion.site/fc24f8ba29c34f9eb30eb945c621c1ca"

fun moveToUrl(context : Context, url : String){
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
context.startActivity(intent)
}catch (e :Exception ){
Toast.makeText(context,"브라우저를 찾을 수 없습니다.", Toast.LENGTH_SHORT).show()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.yapp.feature.home.setting

import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -46,13 +44,11 @@ fun SettingRoute(
}

SettingSideEffect.OpenPrivacyPolicy -> {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(Url.PRIVACY_POLICY))
context.startActivity(intent)
Url.moveToUrl(context, Url.PRIVACY_POLICY)
}

SettingSideEffect.OpenTerms -> {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(Url.TERMS))
context.startActivity(intent)
Url.moveToUrl(context, Url.TERMS)
}

SettingSideEffect.OpenInquiry -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ data class LoginState(
val showAgreementDialog: Boolean = false,
val terms: Boolean = false,
val personalPolicy: Boolean = false,
val isResponseLogin: Boolean = true,
val isLoginEnabled: Boolean = true,
) {
val enableLoginButton: Boolean = email.isNotEmpty() && password.isNotEmpty() && isResponseLogin
val enableLoginButton: Boolean = email.isNotEmpty() && password.isNotEmpty() && isLoginEnabled
val enableNextButton: Boolean = terms && personalPolicy
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.yapp.feature.login

import android.content.Intent
import android.net.Uri
import android.widget.Toast
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -41,13 +39,11 @@ internal fun LoginRoute(
when (effect) {
LoginSideEffect.NavigateToSignUp -> navigateToSignup()
LoginSideEffect.ShowTerms -> {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(Url.TERMS))
context.startActivity(intent)
Url.moveToUrl(context, Url.TERMS)
}

LoginSideEffect.ShowPersonalPolicy -> {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(Url.PRIVACY_POLICY))
context.startActivity(intent)
Url.moveToUrl(context, Url.PRIVACY_POLICY)
}

LoginSideEffect.NavigateToHome -> navigateToHome()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class LoginViewModel @Inject constructor(
is LoginIntent.ClickSignUpButton -> reduce { copy(showAgreementDialog = true) }
is LoginIntent.ChangeEmail -> reduce {
copy(
isResponseLogin = true,
isLoginEnabled = true,
emailErrorDescription = null,
email = intent.email
)
}

is LoginIntent.ChangePassword -> reduce {
copy(
isResponseLogin = true,
isLoginEnabled = true,
passwordErrorDescription = null,
password = intent.password
)
Expand Down Expand Up @@ -87,7 +87,7 @@ class LoginViewModel @Inject constructor(
if (!email.matches(Regex.email)){
reduce {
copy(
isResponseLogin = false,
isLoginEnabled = false,
emailErrorDescription = "입력하신 이메일을 확인해주세요.",
passwordErrorDescription = null
)
Expand All @@ -100,7 +100,7 @@ class LoginViewModel @Inject constructor(
}
.onFailure {
val errorMessage = it.message ?: ""
reduce{copy(isResponseLogin = false)}
reduce{copy(isLoginEnabled = false)}
when (it) {
is InvalidRequestArgument -> {
reduce {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ private fun LoginScreenPreview() {
YappTheme {
Column {
LoginInputSection(
"",
"",
{},
{},
false,
{},
null,
null
email = "",
password = "",
onEmailChange = {},
onPasswordChange = {},
buttonEnable = false,
onButtonClick = {},
emailErrorDescription = null,
passwordErrorDescription = null
)
}
}
Expand Down

0 comments on commit d5d9768

Please sign in to comment.