From d6386266238021747ce773f70904b4a936cbdd88 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Wed, 31 Jan 2024 15:28:44 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B4=89=ED=88=AC=20=ED=8E=B8=EC=A7=91?= =?UTF-8?q?=20=EC=84=9C=EB=B2=84=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../envelope/EditReceivedEnvelopeUseCase.kt | 4 ++- .../susu/feature/navigator/MainNavigator.kt | 12 ++++---- .../ReceivedEnvelopeDetailContract.kt | 2 +- .../ReceivedEnvelopeDetailScreen.kt | 4 +-- .../ReceivedEnvelopeDetailViewModel.kt | 4 ++- .../ReceivedEnvelopeEditScreen.kt | 2 +- .../ReceivedEnvelopeEditViewModel.kt | 30 ++++++++++++++++++- .../ledgerdetail/LedgerDetailContract.kt | 2 +- .../ledgerdetail/LedgerDetailScreen.kt | 4 +-- .../ledgerdetail/LedgerDetailViewModel.kt | 2 +- .../received/navigation/ReceivedNavigation.kt | 26 +++++++++------- 11 files changed, 65 insertions(+), 27 deletions(-) diff --git a/domain/src/main/java/com/susu/domain/usecase/envelope/EditReceivedEnvelopeUseCase.kt b/domain/src/main/java/com/susu/domain/usecase/envelope/EditReceivedEnvelopeUseCase.kt index 83b22a25..ff6a743d 100644 --- a/domain/src/main/java/com/susu/domain/usecase/envelope/EditReceivedEnvelopeUseCase.kt +++ b/domain/src/main/java/com/susu/domain/usecase/envelope/EditReceivedEnvelopeUseCase.kt @@ -20,7 +20,8 @@ class EditReceivedEnvelopeUseCase @Inject constructor( customRelation = customRelation, ) - envelopesRepository.createEnvelope( + envelopesRepository.editEnvelope( + id = envelopeId, type = "RECEIVED", friendId = friendId, ledgerId = ledgerId, @@ -34,6 +35,7 @@ class EditReceivedEnvelopeUseCase @Inject constructor( } data class Param( + val envelopeId: Long, val friendId: Long, val friendName: String, val phoneNumber: String? = null, diff --git a/feature/navigator/src/main/java/com/susu/feature/navigator/MainNavigator.kt b/feature/navigator/src/main/java/com/susu/feature/navigator/MainNavigator.kt index 3573806f..42e9adf7 100644 --- a/feature/navigator/src/main/java/com/susu/feature/navigator/MainNavigator.kt +++ b/feature/navigator/src/main/java/com/susu/feature/navigator/MainNavigator.kt @@ -59,8 +59,8 @@ internal class MainNavigator( in listOf( ReceivedRoute.ledgerSearchRoute, ReceivedRoute.ledgerFilterRoute("{${ReceivedRoute.FILTER_ARGUMENT_NAME}}"), - ReceivedRoute.envelopeDetailRoute("{${ReceivedRoute.ENVELOPE_ARGUMENT_NAME}}"), - ReceivedRoute.envelopeEditRoute("{${ReceivedRoute.ENVELOPE_ARGUMENT_NAME}}"), + ReceivedRoute.envelopeDetailRoute("{${ReceivedRoute.ENVELOPE_ARGUMENT_NAME}}", "{${ReceivedRoute.LEDGER_ID_ARGUMENT_NAME}}"), + ReceivedRoute.envelopeEditRoute("{${ReceivedRoute.ENVELOPE_ARGUMENT_NAME}}", "{${ReceivedRoute.LEDGER_ID_ARGUMENT_NAME}}"), SentRoute.sentEnvelopeRoute, SentRoute.sentEnvelopeDetailRoute, SentRoute.sentEnvelopeEditRoute, @@ -168,12 +168,12 @@ internal class MainNavigator( navController.navigateMyPagePrivacyPolicy() } - fun navigateReceivedEnvelopeDetail(envelope: Envelope) { - navController.navigateReceivedEnvelopeDetail(envelope) + fun navigateReceivedEnvelopeDetail(envelope: Envelope, ledgerId: Long) { + navController.navigateReceivedEnvelopeDetail(envelope, ledgerId) } - fun navigateReceivedEnvelopeEdit(envelope: Envelope) { - navController.navigateReceivedEnvelopeEdit(envelope) + fun navigateReceivedEnvelopeEdit(envelope: Envelope, ledgerId: Long) { + navController.navigateReceivedEnvelopeEdit(envelope, ledgerId) } fun navigateVoteAdd() { diff --git a/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailContract.kt b/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailContract.kt index 14f49e23..bda1f1cf 100644 --- a/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailContract.kt +++ b/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailContract.kt @@ -9,7 +9,7 @@ data class ReceivedEnvelopeDetailState( ) : UiState sealed interface ReceivedEnvelopeDetailSideEffect : SideEffect { - data class NavigateReceivedEnvelopeEdit(val envelope: Envelope) : ReceivedEnvelopeDetailSideEffect + data class NavigateReceivedEnvelopeEdit(val envelope: Envelope, val ledgerId: Long) : ReceivedEnvelopeDetailSideEffect data class PopBackStackWithReceivedEnvelope(val envelope: String) : ReceivedEnvelopeDetailSideEffect data class PopBackStackWithDeleteReceivedEnvelopeId(val envelopeId: Long) : ReceivedEnvelopeDetailSideEffect data class ShowDeleteDialog(val onConfirmRequest: () -> Unit) : ReceivedEnvelopeDetailSideEffect diff --git a/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailScreen.kt b/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailScreen.kt index 84bbaa1f..4949e5d5 100644 --- a/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailScreen.kt +++ b/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailScreen.kt @@ -41,7 +41,7 @@ fun ReceivedEnvelopeDetailRoute( viewModel: ReceivedEnvelopeDetailViewModel = hiltViewModel(), popBackStackWithDeleteReceivedEnvelopeId: (Long) -> Unit, popBackStackWithReceivedEnvelope: (String) -> Unit, - navigateReceivedEnvelopeEdit: (Envelope) -> Unit, + navigateReceivedEnvelopeEdit: (Envelope, Long) -> Unit, handleException: (Throwable, () -> Unit) -> Unit, onShowSnackbar: (SnackbarToken) -> Unit, onShowDialog: (DialogToken) -> Unit, @@ -51,7 +51,7 @@ fun ReceivedEnvelopeDetailRoute( viewModel.sideEffect.collectWithLifecycle { sideEffect -> when (sideEffect) { is ReceivedEnvelopeDetailSideEffect.HandleException -> handleException(sideEffect.throwable, sideEffect.retry) - is ReceivedEnvelopeDetailSideEffect.NavigateReceivedEnvelopeEdit -> navigateReceivedEnvelopeEdit(sideEffect.envelope) + is ReceivedEnvelopeDetailSideEffect.NavigateReceivedEnvelopeEdit -> navigateReceivedEnvelopeEdit(sideEffect.envelope, sideEffect.ledgerId) is ReceivedEnvelopeDetailSideEffect.PopBackStackWithDeleteReceivedEnvelopeId -> popBackStackWithDeleteReceivedEnvelopeId( sideEffect.envelopeId, ) diff --git a/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailViewModel.kt b/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailViewModel.kt index 50367c6a..d189c751 100644 --- a/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailViewModel.kt +++ b/feature/received/src/main/java/com/susu/feature/received/envelopedetail/ReceivedEnvelopeDetailViewModel.kt @@ -24,6 +24,8 @@ class ReceivedEnvelopeDetailViewModel @Inject constructor( ReceivedEnvelopeDetailState(), ) { private val argument = savedStateHandle.get(ReceivedRoute.ENVELOPE_ARGUMENT_NAME)!! + private val ledgerId = savedStateHandle.get(ReceivedRoute.LEDGER_ID_ARGUMENT_NAME)!!.toLong() + private var envelope = Envelope() fun getEnvelope() = viewModelScope.launch { @@ -39,7 +41,7 @@ class ReceivedEnvelopeDetailViewModel @Inject constructor( } } - fun navigateEnvelopeEdit() = postSideEffect(ReceivedEnvelopeDetailSideEffect.NavigateReceivedEnvelopeEdit(envelope)) + fun navigateEnvelopeEdit() = postSideEffect(ReceivedEnvelopeDetailSideEffect.NavigateReceivedEnvelopeEdit(envelope, ledgerId)) fun popBackStackWithEnvelope() = postSideEffect(ReceivedEnvelopeDetailSideEffect.PopBackStackWithReceivedEnvelope(Json.encodeToUri(envelope))) fun showDeleteDialog() = postSideEffect( ReceivedEnvelopeDetailSideEffect.ShowDeleteDialog( diff --git a/feature/received/src/main/java/com/susu/feature/received/envelopeedit/ReceivedEnvelopeEditScreen.kt b/feature/received/src/main/java/com/susu/feature/received/envelopeedit/ReceivedEnvelopeEditScreen.kt index f0bf7710..a7c8e38b 100644 --- a/feature/received/src/main/java/com/susu/feature/received/envelopeedit/ReceivedEnvelopeEditScreen.kt +++ b/feature/received/src/main/java/com/susu/feature/received/envelopeedit/ReceivedEnvelopeEditScreen.kt @@ -88,7 +88,7 @@ fun ReceivedEnvelopeEditRoute( uiState = uiState, focusRequester = focusRequester, onClickBackIcon = viewModel::popBackStack, - onClickSave = {}, + onClickSave = viewModel::editReceivedEnvelope, onTextChangeMoney = viewModel::updateMoney, onTextChangeName = viewModel::updateName, onTextChangeRelation = viewModel::updateCustomRelation, diff --git a/feature/received/src/main/java/com/susu/feature/received/envelopeedit/ReceivedEnvelopeEditViewModel.kt b/feature/received/src/main/java/com/susu/feature/received/envelopeedit/ReceivedEnvelopeEditViewModel.kt index c2772641..cbb5189c 100644 --- a/feature/received/src/main/java/com/susu/feature/received/envelopeedit/ReceivedEnvelopeEditViewModel.kt +++ b/feature/received/src/main/java/com/susu/feature/received/envelopeedit/ReceivedEnvelopeEditViewModel.kt @@ -10,6 +10,7 @@ import com.susu.core.ui.base.SideEffect import com.susu.core.ui.extension.decodeFromUri import com.susu.core.ui.extension.encodeToUri import com.susu.domain.usecase.envelope.DeleteEnvelopeUseCase +import com.susu.domain.usecase.envelope.EditReceivedEnvelopeUseCase import com.susu.domain.usecase.envelope.GetEnvelopeUseCase import com.susu.domain.usecase.envelope.GetRelationShipConfigListUseCase import com.susu.feature.received.navigation.ReceivedRoute @@ -25,11 +26,13 @@ import javax.inject.Inject @HiltViewModel class ReceivedEnvelopeEditViewModel @Inject constructor( private val getRelationShipConfigListUseCase: GetRelationShipConfigListUseCase, + private val editReceivedEnvelopeUseCase: EditReceivedEnvelopeUseCase, savedStateHandle: SavedStateHandle, ) : BaseViewModel( ReceivedEnvelopeEditState(), ) { private val argument = savedStateHandle.get(ReceivedRoute.ENVELOPE_ARGUMENT_NAME)!! + private val ledgerId = savedStateHandle.get(ReceivedRoute.LEDGER_ID_ARGUMENT_NAME)!!.toLong() private var isFirstVisited: Boolean = true @@ -55,6 +58,31 @@ class ReceivedEnvelopeEditViewModel @Inject constructor( } } + fun editReceivedEnvelope() = viewModelScope.launch { + editReceivedEnvelopeUseCase( + param = with(currentState) { + EditReceivedEnvelopeUseCase.Param( + envelopeId = envelope.id, + friendId = envelope.friend.id, + friendName = envelope.friend.name, + phoneNumber = envelope.friend.phoneNumber.ifEmpty { null }, + relationshipId = envelope.relationship.id, + customRelation = envelope.relationship.customRelation, + ledgerId = ledgerId, + amount = envelope.amount, + gift = envelope.gift, + memo = envelope.memo, + handedOverAt = envelope.handedOverAt, + hasVisited = envelope.hasVisited, + ) + } + ).onSuccess { + popBackStack() + }.onFailure { + postSideEffect(ReceivedEnvelopeEditSideEffect.HandleException(it, ::editReceivedEnvelope)) + } + } + fun popBackStack() = postSideEffect(ReceivedEnvelopeEditSideEffect.PopBackStack) @@ -66,7 +94,7 @@ class ReceivedEnvelopeEditViewModel @Inject constructor( fun updateName(name: String) = intent { copy( - envelope = envelope.copy(friend = Friend(name = name)), + envelope = envelope.copy(friend = envelope.friend.copy(name = name)), ) } diff --git a/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailContract.kt b/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailContract.kt index 3b555cbc..3ddaae39 100644 --- a/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailContract.kt +++ b/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailContract.kt @@ -20,7 +20,7 @@ data class LedgerDetailState( sealed interface LedgerDetailSideEffect : SideEffect { data class NavigateEnvelopeAdd(val categoryName: String, val ledgerId: Long) : LedgerDetailSideEffect - data class NavigateEnvelopeDetail(val envelope: Envelope) : LedgerDetailSideEffect + data class NavigateEnvelopeDetail(val envelope: Envelope, val ledgerId: Long) : LedgerDetailSideEffect data class NavigateLedgerEdit(val ledger: Ledger) : LedgerDetailSideEffect data class PopBackStackWithLedger(val ledger: String) : LedgerDetailSideEffect data class PopBackStackWithDeleteLedgerId(val ledgerId: Long) : LedgerDetailSideEffect diff --git a/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailScreen.kt b/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailScreen.kt index ab760394..2da3f53c 100644 --- a/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailScreen.kt +++ b/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailScreen.kt @@ -59,7 +59,7 @@ fun LedgerDetailRoute( toDeleteEnvelopeId: Long?, navigateLedgerEdit: (Ledger) -> Unit, navigateEnvelopAdd: (String, Long) -> Unit, - navigateEnvelopeDetail: (Envelope) -> Unit, + navigateEnvelopeDetail: (Envelope, Long) -> Unit, popBackStackWithLedger: (String) -> Unit, popBackStackWithDeleteLedgerId: (Long) -> Unit, onShowSnackbar: (SnackbarToken) -> Unit, @@ -97,7 +97,7 @@ fun LedgerDetailRoute( is LedgerDetailSideEffect.HandleException -> handleException(sideEffect.throwable, sideEffect.retry) is LedgerDetailSideEffect.ShowSnackbar -> onShowSnackbar(SnackbarToken(message = sideEffect.msg)) is LedgerDetailSideEffect.NavigateEnvelopeAdd -> navigateEnvelopAdd(sideEffect.categoryName, sideEffect.ledgerId) - is LedgerDetailSideEffect.NavigateEnvelopeDetail -> navigateEnvelopeDetail(sideEffect.envelope) + is LedgerDetailSideEffect.NavigateEnvelopeDetail -> navigateEnvelopeDetail(sideEffect.envelope, sideEffect.ledgerId) } } diff --git a/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailViewModel.kt b/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailViewModel.kt index 35a1ea41..1457d05b 100644 --- a/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailViewModel.kt +++ b/feature/received/src/main/java/com/susu/feature/received/ledgerdetail/LedgerDetailViewModel.kt @@ -175,5 +175,5 @@ class LedgerDetailViewModel @Inject constructor( LedgerDetailSideEffect.NavigateEnvelopeAdd(ledger.category.customCategory ?: ledger.category.name, ledger.id), ) - fun navigateEnvelopeDetail(envelope: Envelope) = postSideEffect(LedgerDetailSideEffect.NavigateEnvelopeDetail(envelope)) + fun navigateEnvelopeDetail(envelope: Envelope) = postSideEffect(LedgerDetailSideEffect.NavigateEnvelopeDetail(envelope, ledger.id)) } diff --git a/feature/received/src/main/java/com/susu/feature/received/navigation/ReceivedNavigation.kt b/feature/received/src/main/java/com/susu/feature/received/navigation/ReceivedNavigation.kt index b9117123..a464b0d9 100644 --- a/feature/received/src/main/java/com/susu/feature/received/navigation/ReceivedNavigation.kt +++ b/feature/received/src/main/java/com/susu/feature/received/navigation/ReceivedNavigation.kt @@ -52,12 +52,12 @@ fun NavController.navigateReceivedEnvelopeAdd(categoryName: String, ledgerId: Lo navigate(ReceivedRoute.envelopeAddRoute(categoryName, ledgerId.toString())) } -fun NavController.navigateReceivedEnvelopeDetail(envelope: Envelope) { - navigate(ReceivedRoute.envelopeDetailRoute(Json.encodeToUri(envelope))) +fun NavController.navigateReceivedEnvelopeDetail(envelope: Envelope, ledgerId: Long) { + navigate(ReceivedRoute.envelopeDetailRoute(Json.encodeToUri(envelope), ledgerId.toString())) } -fun NavController.navigateReceivedEnvelopeEdit(envelope: Envelope) { - navigate(ReceivedRoute.envelopeEditRoute(Json.encodeToUri(envelope))) +fun NavController.navigateReceivedEnvelopeEdit(envelope: Envelope, ledgerId: Long) { + navigate(ReceivedRoute.envelopeEditRoute(Json.encodeToUri(envelope), ledgerId.toString())) } @Suppress("detekt:LongMethod") @@ -73,8 +73,8 @@ fun NavGraphBuilder.receivedNavGraph( navigateLedgerFilter: (FilterArgument) -> Unit, navigateLedgerAdd: () -> Unit, navigateEnvelopAdd: (String, Long) -> Unit, - navigateEnvelopeDetail: (Envelope) -> Unit, - navigateEnvelopeEdit: (Envelope) -> Unit, + navigateEnvelopeDetail: (Envelope, Long) -> Unit, + navigateEnvelopeEdit: (Envelope, Long) -> Unit, popBackStackWithEnvelope: (String) -> Unit, popBackStackWithDeleteReceivedEnvelopeId: (Long) -> Unit, onShowSnackbar: (SnackbarToken) -> Unit, @@ -176,7 +176,10 @@ fun NavGraphBuilder.receivedNavGraph( } composable( - route = ReceivedRoute.envelopeDetailRoute("{${ReceivedRoute.ENVELOPE_ARGUMENT_NAME}}"), + route = ReceivedRoute.envelopeDetailRoute( + envelope = "{${ReceivedRoute.ENVELOPE_ARGUMENT_NAME}}", + ledgerId = "{${ReceivedRoute.LEDGER_ID_ARGUMENT_NAME}}", + ), ) { ReceivedEnvelopeDetailRoute( popBackStackWithDeleteReceivedEnvelopeId = popBackStackWithDeleteReceivedEnvelopeId, @@ -189,7 +192,10 @@ fun NavGraphBuilder.receivedNavGraph( } composable( - route = ReceivedRoute.envelopeEditRoute("{${ReceivedRoute.ENVELOPE_ARGUMENT_NAME}}"), + route = ReceivedRoute.envelopeEditRoute( + envelope = "{${ReceivedRoute.ENVELOPE_ARGUMENT_NAME}}", + ledgerId = "{${ReceivedRoute.LEDGER_ID_ARGUMENT_NAME}}", + ), ) { ReceivedEnvelopeEditRoute( popBackStack = popBackStack, @@ -215,6 +221,6 @@ object ReceivedRoute { const val ledgerAddRoute = "ledger-add" fun envelopeAddRoute(categoryName: String, ledgerId: String) = "envelope-add/$categoryName/$ledgerId" - fun envelopeDetailRoute(envelope: String) = "envelope-detail/$envelope" - fun envelopeEditRoute(envelope: String) = "envelope-edit/$envelope" + fun envelopeDetailRoute(envelope: String, ledgerId: String) = "envelope-detail/$envelope/$ledgerId" + fun envelopeEditRoute(envelope: String, ledgerId: String) = "envelope-edit/$envelope/$ledgerId" }