-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix/#871] 마이페이지 오류 수정 #907
Changes from 20 commits
b91142f
661e1b5
44b6727
ec9c02d
749226f
f6a3495
9d9b32c
6270326
9eec6da
70f077e
eb25798
7194eff
2afdbfc
a994e4b
880fb19
eea9cc4
adf5d5b
fdfaf0b
b12835f
9b6b873
c487625
7746918
2f50399
8dc7cac
8bac4ac
abd79f9
f8d30f3
482e355
8fd8527
6083cb9
e22c296
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ package org.sopt.official.auth.impl.remote | |
import javax.inject.Inject | ||
import org.sopt.official.auth.impl.api.AuthService | ||
import org.sopt.official.auth.impl.model.response.LogOutRequest | ||
import org.sopt.official.auth.impl.model.response.LogOutResponse | ||
import org.sopt.official.auth.impl.source.RemoteAuthDataSource | ||
import org.sopt.official.common.di.Auth | ||
import org.sopt.official.network.model.request.RefreshRequest | ||
|
@@ -46,7 +45,7 @@ class DefaultRemoteAuthDataSource @Inject constructor( | |
authService.withdraw() | ||
} | ||
|
||
override suspend fun logout(request: LogOutRequest): LogOutResponse { | ||
return authService.logOut(request) | ||
override suspend fun logout(request: LogOutRequest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개인적으로 data 레이어에서 로그인 혹은 로그아웃이라는 함수 네이밍을 지양하는 편입니다! 저장소 역할을 담당하는 객체가 로그아웃이라는 책임이 있다고 생각하지 않아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @s9hn 그러면 함수 네이밍 추천좀... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅋ한번쯤은 고민해보셔야지~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저장소는 CRUD 관련된 prefix만을 사용하려고 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앱을 사용하는 입장에서 보면 유저 상태를 날리는 함수인데 save, fetch라....논리적으로 맞지 않는다고 생각하는데 어떻게 생각하시나요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앱을 사용하는 입장에서 보는게 잘못된 입장이라고 생각해요! |
||
authService.logOut(request) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ class AuthRepositoryImpl @Inject constructor( | |
remoteAuthDataSource.withdraw() | ||
} | ||
|
||
override suspend fun logout(pushToken: String): Result<Unit> = runCatching { | ||
override suspend fun logout(pushToken: String) = runCatching { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 토큰은 로컬 저장소에 저장 및 관리되고 있고 로그아웃은 무조건 본인의 토큰만을 보낼 것 같은데 파라미터로 받는 이유가 있으신가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pushToken을 파라미터로 받을 이유가 없다는 말씀이신가요..?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하 저도 실제 사용처 찾아보니 파이어베이스 토큰을 호출해서 넣어주고 있었네요. |
||
remoteAuthDataSource.logout( | ||
LogOutRequest( | ||
platform = "Android", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,6 @@ import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
|
@@ -51,7 +50,6 @@ import androidx.compose.ui.unit.dp | |
import androidx.lifecycle.compose.LocalLifecycleOwner | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.lifecycle.flowWithLifecycle | ||
import com.jakewharton.processphoenix.ProcessPhoenix | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.collections.immutable.persistentListOf | ||
import org.sopt.official.auth.model.UserActiveState | ||
|
@@ -84,8 +82,7 @@ class MyPageActivity : AppCompatActivity() { | |
val context = LocalContext.current | ||
val lifecycleOwner = LocalLifecycleOwner.current | ||
|
||
val isAuthenticated by viewModel.userActiveState.collectAsStateWithLifecycle(initialValue = false) | ||
val dialogState by viewModel.dialogState.collectAsStateWithLifecycle() | ||
val state by viewModel.state.collectAsStateWithLifecycle() | ||
val scrollState = rememberScrollState() | ||
|
||
val serviceSectionItems = remember { | ||
|
@@ -156,34 +153,25 @@ class MyPageActivity : AppCompatActivity() { | |
MyPageUiModel.MyPageItem( | ||
title = "로그인", | ||
onItemClick = { | ||
onBackPressedDispatcher.onBackPressed() | ||
startActivity(navigatorProvider.getAuthActivityIntent()) | ||
} | ||
) | ||
) | ||
} | ||
|
||
LaunchedEffect(Unit) { | ||
args?.userActiveState?.let { | ||
viewModel.setUserActiveState(MyPageUiState.User(it)) | ||
viewModel.setUserActiveState(it) | ||
} | ||
} | ||
|
||
LaunchedEffect(viewModel.finish, lifecycleOwner) { | ||
viewModel.finish.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle) | ||
.collect { | ||
ProcessPhoenix.triggerRebirth(context, navigatorProvider.getAuthActivityIntent()) | ||
startActivity(navigatorProvider.getAuthActivityIntent()) | ||
} | ||
} | ||
|
||
if (dialogState is MyPageUiState.Dialog) { | ||
ShowMyPageDialog( | ||
action = (dialogState as MyPageUiState.Dialog).action, | ||
onDismissRequest = viewModel::onDismiss, | ||
onClearSoptampClick = viewModel::resetSoptamp, | ||
onLogoutClick = viewModel::logOut | ||
) | ||
} | ||
|
||
Scaffold(modifier = Modifier | ||
.background(SoptTheme.colors.background) | ||
.fillMaxSize(), | ||
|
@@ -204,14 +192,45 @@ class MyPageActivity : AppCompatActivity() { | |
Spacer(modifier = Modifier.height(20.dp)) | ||
MyPageSection(items = serviceSectionItems) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
if (isAuthenticated) { | ||
MyPageSection(items = notificationSectionItems) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
MyPageSection(items = soptampSectionItems) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
MyPageSection(items = etcSectionItems) | ||
} else { | ||
MyPageSection(items = etcLoginSectionItems) | ||
when (state) { | ||
is MyPageUiState.Authenticated -> { | ||
when ((state as MyPageUiState.Authenticated).action) { | ||
MyPageAction.CLEAR_SOPTAMP -> { | ||
MyPageDialog( | ||
onDismissRequest = viewModel::onDismiss, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dismiss시 수행해야할 동작이 omDismiss인것은 어떤 동작인지 파악하기 힘들 것 같아요. 아래 resetSoptamp처럼 함수가 해야할 일을 직관적으로 적어도 좋을 것 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수명에 조금 더 신경 써야겠네요..!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 MyPageDialog가 섹션들 사이에 있는 지 이유가 따로 있을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 처음에 코드를 작성할 때는 |
||
title = "미션을 초기화 하실건가요?", | ||
subTitle = "사진, 메모가 삭제되고\n전체 미션이 미완료상태로 초기화됩니다.", | ||
negativeText = "취소", | ||
positiveText = "초기화", | ||
onPositiveButtonClick = viewModel::resetSoptamp | ||
) | ||
} | ||
|
||
MyPageAction.LOGOUT -> { | ||
MyPageDialog( | ||
onDismissRequest = viewModel::onDismiss, | ||
title = "로그아웃", | ||
subTitle = "정말 로그아웃을 하실 건가요?", | ||
negativeText = "취소", | ||
positiveText = "로그아웃", | ||
onPositiveButtonClick = viewModel::logOut | ||
) | ||
} | ||
|
||
else -> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 가급적이면 sealed나 enum으로 else 분기 없애주는게 좋긴한데 정 안되면 Unit이나 정말 else로 갈 수가 없는 경우이면 익셉션 혹은 에러뷰를 나타내도 괜찮겠어요 |
||
} | ||
MyPageSection(items = notificationSectionItems) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
MyPageSection(items = soptampSectionItems) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
MyPageSection(items = etcSectionItems) | ||
} | ||
|
||
is MyPageUiState.UnAuthenticated -> { | ||
MyPageSection(items = etcLoginSectionItems) | ||
} | ||
|
||
is MyPageUiState.UnInitialized -> {} | ||
} | ||
Spacer(modifier = Modifier.height(32.dp)) | ||
} | ||
|
@@ -231,35 +250,3 @@ class MyPageActivity : AppCompatActivity() { | |
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ShowMyPageDialog( | ||
action: MyPageAction, | ||
onDismissRequest: () -> Unit, | ||
onClearSoptampClick: () -> Unit, | ||
onLogoutClick: () -> Unit | ||
) { | ||
when (action) { | ||
MyPageAction.CLEAR_SOPTAMP -> { | ||
MyPageDialog( | ||
onDismissRequest = onDismissRequest, | ||
title = "미션을 초기화 하실건가요?", | ||
subTitle = "사진, 메모가 삭제되고\n전체 미션이 미완료상태로 초기화됩니다.", | ||
negativeText = "취소", | ||
positiveText = "초기화", | ||
onPositiveButtonClick = onClearSoptampClick | ||
) | ||
} | ||
|
||
MyPageAction.LOGOUT -> { | ||
MyPageDialog( | ||
onDismissRequest = onDismissRequest, | ||
title = "로그아웃", | ||
subTitle = "정말 로그아웃을 하실 건가요?", | ||
negativeText = "취소", | ||
positiveText = "로그아웃", | ||
onPositiveButtonClick = onLogoutClick | ||
) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,8 @@ import kotlinx.coroutines.channels.Channel | |
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.filterIsInstance | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.receiveAsFlow | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.tasks.await | ||
import org.sopt.official.auth.model.UserActiveState | ||
|
@@ -54,18 +53,15 @@ class MyPageViewModel @Inject constructor( | |
private val stampRepository: StampRepository, | ||
) : ViewModel() { | ||
|
||
private val _userActiveState = MutableStateFlow<MyPageUiState>(MyPageUiState.UnInitialized) | ||
val userActiveState = _userActiveState.filterIsInstance<MyPageUiState.User>() | ||
.map { it.activeState != UserActiveState.UNAUTHENTICATED } | ||
|
||
private val _dialogState: MutableStateFlow<MyPageUiState> = MutableStateFlow(MyPageUiState.UnInitialized) | ||
val dialogState: StateFlow<MyPageUiState> = _dialogState.asStateFlow() | ||
private val _state: MutableStateFlow<MyPageUiState> = MutableStateFlow(MyPageUiState.UnInitialized) | ||
val state: StateFlow<MyPageUiState> = _state.asStateFlow() | ||
|
||
private val _finish = Channel<Unit>() | ||
val finish = _finish.receiveAsFlow() | ||
|
||
fun setUserActiveState(new: MyPageUiState) { | ||
_userActiveState.value = new | ||
fun setUserActiveState(activeState: UserActiveState) { | ||
if (activeState == UserActiveState.UNAUTHENTICATED) _state.value = MyPageUiState.UnAuthenticated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아래에선 update를 사용하는데 여기선 세터로 다르게 사용하는 이유가 있나용 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예리하시군요.. 다른 이유가 있었던 건 아니었습니다..! 코드 통일시켜두도록 하겠습니다! |
||
else _state.value = MyPageUiState.Authenticated(activeState) | ||
} | ||
|
||
fun logOut() { | ||
|
@@ -87,16 +83,20 @@ class MyPageViewModel @Inject constructor( | |
fun resetSoptamp() { | ||
viewModelScope.launch { | ||
stampRepository.deleteAllStamps() | ||
.onSuccess { onDismiss() } | ||
.onFailure { Timber.e(it) } | ||
} | ||
} | ||
|
||
fun showDialogState(action: MyPageAction) { | ||
_dialogState.tryEmit(MyPageUiState.Dialog(action)) | ||
_state.update { currentState -> | ||
(currentState as MyPageUiState.Authenticated).copy(action = action) | ||
} | ||
} | ||
|
||
fun onDismiss() { | ||
_dialogState.tryEmit(MyPageUiState.UnInitialized) | ||
_state.update { currentState -> | ||
(currentState as MyPageUiState.Authenticated).copy(action = null) | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 그냥 궁금한건데 Delete 어노테이션과 차이가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete에 body 값이 안들어가는게 원칙인데 굳이 넣어줘야할 때에는 이렇게 사용하는걸로 알고 있음
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저거 무시하고 그냥 body 패러미터 넣으면 에러 일으킴ㅋㅋㅋ
그래서 원칙적으로는
인데 난 갠적으로 1로 쇼부치는게 더 깔끔하다고 생각하긴함. (정 안되면 2번)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오.. 신기하네 하나 알아갑니다. 저도 같은이유라면 서버에게 요청하고 안되면 뭐 2번해야쥬