Skip to content

Commit

Permalink
Merge pull request #178 from Team-Notitime/feat/my-page/176-withdrawa…
Browse files Browse the repository at this point in the history
…l-api

Feat/my page/176 withdrawal api
  • Loading branch information
easyhz authored Aug 29, 2024
2 parents 4be7fc5 + fc938b1 commit cb301c2
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.easyhz.noffice.core.network.model.request.sign.LoginRequest
import com.easyhz.noffice.core.network.model.response.auth.UserResponse
import com.easyhz.noffice.core.network.util.NofficeResult
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.Header
import retrofit2.http.POST

Expand All @@ -15,7 +16,7 @@ interface AuthService {
@Body body: LoginRequest
): NofficeResult<UserResponse>

/* 로그아웃 */
/* 로그 아웃 */
@POST("/api/v1/member/logout")
suspend fun logout(
@Header("notification-token") notificationToken: String
Expand All @@ -26,4 +27,8 @@ interface AuthService {
suspend fun registerMessagingToken(
@Body fcmToken: String
): NofficeResult<Unit>

/* 회원 탈퇴 */
@DELETE("/api/v1/member/withdrawal")
suspend fun withdrawal(): NofficeResult<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import android.content.Context
interface AuthRepository {
suspend fun login(context: Context, provider: String): Result<Unit>
suspend fun logout(context: Context): Result<Unit>
suspend fun withdraw(context: Context): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ class AuthRepositoryIml @Inject constructor(
override suspend fun logout(context: Context): Result<Unit> = withContext(dispatcher) {
runCatching {
logoutFromServer()
val provider = getAuthProvider().getOrThrow()
authStrategyContext.setStrategy(provider)
val logoutJob = async { authStrategyContext.logout(context) }
val deleteJob = async { deleteLocalUserInfo() }
localLogout(context)
Unit
}
}

awaitAll(logoutJob, deleteJob)
override suspend fun withdraw(context: Context): Result<Unit> = withContext(dispatcher) {
runCatching {
authService.withdrawal().toResult()
localLogout(context)
Unit
}
}
Expand All @@ -62,6 +65,20 @@ class AuthRepositoryIml @Inject constructor(
awaitAll(authJob, userJob)
}

/**
* 로컬에서 로그아웃을 처리합니다.
*/
private suspend fun localLogout(context: Context) = coroutineScope {
val provider = getAuthProvider().getOrThrow()
authStrategyContext.setStrategy(provider)
val logoutJob = async { authStrategyContext.logout(context) }
val deleteJob = async { deleteLocalUserInfo() }
awaitAll(logoutJob, deleteJob)
}

/**
* 로컬에 저장된 유저 정보를 삭제합니다.
*/
private suspend fun deleteLocalUserInfo() = coroutineScope {
val authJob = async {
authLocalDataSource.deleteToken()
Expand All @@ -73,12 +90,18 @@ class AuthRepositoryIml @Inject constructor(
awaitAll(authJob, userJob)
}

/**
* 로컬에 저장된 인증 방식을 가져옵니다.
*/
private suspend fun getAuthProvider(): Result<String> {
return authLocalDataSource.getAuthProvider()
}

/**
* 서버에서 로그아웃을 처리합니다.
*/
private suspend fun logoutFromServer() {
val token = cloudMessagingRepository.getToken().getOrThrow()
authService.logout(token)
authService.logout(token).toResult()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.easyhz.noffice.domain.my_page.usecase

import android.content.Context
import com.easyhz.noffice.core.common.base.BaseUseCase
import com.easyhz.noffice.data.auth.repository.auth.AuthRepository
import javax.inject.Inject

class WithdrawUserCase @Inject constructor(
private val authRepository: AuthRepository
): BaseUseCase<Context, Unit>() {
override suspend fun invoke(param: Context): Result<Unit> {
return authRepository.withdraw(param)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.easyhz.noffice.feature.my_page.contract.detail.withdrawal

import android.content.Context
import com.easyhz.noffice.core.common.base.UiIntent

sealed class WithdrawalIntent: UiIntent() {
data object ClickBackButton: WithdrawalIntent()
data object ClickConsentButton: WithdrawalIntent()
data object ClickWithdrawalButton: WithdrawalIntent()
data class ClickWithdrawalButton(val context: Context): WithdrawalIntent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.easyhz.noffice.core.common.base.UiSideEffect

sealed class WithdrawalSideEffect: UiSideEffect() {
data object NavigateToUp: WithdrawalSideEffect()
data object NavigateToLogIn: WithdrawalSideEffect()
data object NavigateToLogin: WithdrawalSideEffect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.easyhz.noffice.feature.my_page.contract.detail.withdrawal
import com.easyhz.noffice.core.common.base.UiState

data class WithdrawalState(
val isChecked: Boolean
val isChecked: Boolean,
val isLoading: Boolean,
): UiState() {
companion object {
fun init() = WithdrawalState(
isChecked = false
isChecked = false,
isLoading = false
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ fun MyPageScreen(
) {
NofficeBasicScaffold(
containerColor = Grey50,
statusBarColor = Grey50,
navigationBarColor = Grey50,
topBar = {
DetailTopBar(
modifier = Modifier.background(Grey50),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -29,6 +30,7 @@ import com.easyhz.noffice.core.common.util.collectInSideEffectWithLifecycle
import com.easyhz.noffice.core.design_system.R
import com.easyhz.noffice.core.design_system.component.button.CircleCheck
import com.easyhz.noffice.core.design_system.component.button.MediumButton
import com.easyhz.noffice.core.design_system.component.loading.LoadingScreenProvider
import com.easyhz.noffice.core.design_system.component.scaffold.NofficeBasicScaffold
import com.easyhz.noffice.core.design_system.component.topBar.DetailTopBar
import com.easyhz.noffice.core.design_system.extension.screenHorizonPadding
Expand All @@ -54,112 +56,119 @@ fun WithdrawalScreen(
navigateToLogin: () -> Unit
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val context = LocalContext.current

NofficeBasicScaffold(
containerColor = Grey50,
LoadingScreenProvider(
isLoading = uiState.isLoading,
statusBarColor = Grey50,
navigationBarColor = Grey50,
topBar = {
DetailTopBar(
modifier = Modifier.background(Grey50),
leadingItem = DetailTopBarMenu(
content = {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.ic_chevron_left),
contentDescription = "left",
tint = Grey400
)
},
onClick = { viewModel.postIntent(WithdrawalIntent.ClickBackButton) }
),
)
},
bottomBar = {
MediumButton(
modifier = Modifier
.screenHorizonPadding()
.fillMaxWidth()
.padding(bottom = 16.dp),
text = stringResource(id = R.string.my_page_menu_withdrawal_button),
enabled = uiState.isChecked
) { viewModel.postIntent(WithdrawalIntent.ClickWithdrawalButton) }
}
) { paddingValues ->
Column(
modifier = modifier
.padding(paddingValues)
.padding(horizontal = 20.dp, vertical = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Column(
modifier = Modifier.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(text = stringResource(id = R.string.my_page_menu_withdrawal), style = SemiBold16, color = Green500)
Text(
text = stringResource(id = R.string.my_page_menu_withdrawal_title),
style = Title3,
lineHeight = (22 * 1.4).sp,
color = Grey800
)
}
Spacer(
modifier = Modifier
.weight(0.1f)
)
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
Image(
painter = painterResource(id = R.drawable.ic_withdrawal),
contentDescription = "withdrawal"
navigationBarColor = Grey50
) {
NofficeBasicScaffold(
containerColor = Grey50,
statusBarColor = Grey50,
navigationBarColor = Grey50,
topBar = {
DetailTopBar(
modifier = Modifier.background(Grey50),
leadingItem = DetailTopBarMenu(
content = {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.ic_chevron_left),
contentDescription = "left",
tint = Grey400
)
},
onClick = { viewModel.postIntent(WithdrawalIntent.ClickBackButton) }
),
)
},
bottomBar = {
MediumButton(
modifier = Modifier
.screenHorizonPadding()
.fillMaxWidth()
.padding(bottom = 16.dp),
text = stringResource(id = R.string.my_page_menu_withdrawal_button),
enabled = uiState.isChecked
) { viewModel.postIntent(WithdrawalIntent.ClickWithdrawalButton(context)) }
}

) { paddingValues ->
Column(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(10.dp))
.background(White)
.padding(16.dp),
modifier = modifier
.padding(paddingValues)
.padding(horizontal = 20.dp, vertical = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Text(text = stringResource(id = R.string.my_page_menu_withdrawal_type_title), style = SemiBold16)
Column(
modifier = Modifier.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
WithdrawalType.entries.forEach {
WithdrawalTypeItem(type = it)
Text(text = stringResource(id = R.string.my_page_menu_withdrawal), style = SemiBold16, color = Green500)
Text(
text = stringResource(id = R.string.my_page_menu_withdrawal_title),
style = Title3,
lineHeight = (22 * 1.4).sp,
color = Grey800
)
}
Spacer(
modifier = Modifier
.weight(0.1f)
)
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
Image(
painter = painterResource(id = R.drawable.ic_withdrawal),
contentDescription = "withdrawal"
)
}

Column(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(10.dp))
.background(White)
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Text(text = stringResource(id = R.string.my_page_menu_withdrawal_type_title), style = SemiBold16)
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
WithdrawalType.entries.forEach {
WithdrawalTypeItem(type = it)
}
}
}
}
Row(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(10.dp))
.background(White)
.clickable { viewModel.postIntent(WithdrawalIntent.ClickConsentButton) }
.padding(16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
CircleCheck(
modifier = Modifier.size(18.dp),
isChecked = uiState.isChecked,
enabled = false
Row(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(10.dp))
.background(White)
.clickable { viewModel.postIntent(WithdrawalIntent.ClickConsentButton) }
.padding(16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
CircleCheck(
modifier = Modifier.size(18.dp),
isChecked = uiState.isChecked,
enabled = false
)
Text(text = stringResource(id = R.string.my_page_menu_withdrawal_consent), style = SubBody14)
}
Spacer(
modifier = Modifier
.weight(0.3f)
)
Text(text = stringResource(id = R.string.my_page_menu_withdrawal_consent), style = SubBody14)
}
Spacer(
modifier = Modifier
.weight(0.3f)
)
}
}

viewModel.sideEffect.collectInSideEffectWithLifecycle { sideEffect ->
when(sideEffect) {
is WithdrawalSideEffect.NavigateToUp -> { navigateToUp() }
is WithdrawalSideEffect.NavigateToLogIn -> { navigateToLogin() }
is WithdrawalSideEffect.NavigateToLogin -> { navigateToLogin() }
}
}
}
Loading

0 comments on commit cb301c2

Please sign in to comment.