Skip to content

Commit

Permalink
feat: 봉투 편집 서버 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
jinukeu committed Jan 31, 2024
1 parent 03db3b9 commit d638626
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class EditReceivedEnvelopeUseCase @Inject constructor(
customRelation = customRelation,
)

envelopesRepository.createEnvelope(
envelopesRepository.editEnvelope(
id = envelopeId,
type = "RECEIVED",
friendId = friendId,
ledgerId = ledgerId,
Expand All @@ -34,6 +35,7 @@ class EditReceivedEnvelopeUseCase @Inject constructor(
}

data class Param(
val envelopeId: Long,
val friendId: Long,
val friendName: String,
val phoneNumber: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ReceivedEnvelopeDetailViewModel @Inject constructor(
ReceivedEnvelopeDetailState(),
) {
private val argument = savedStateHandle.get<String>(ReceivedRoute.ENVELOPE_ARGUMENT_NAME)!!
private val ledgerId = savedStateHandle.get<String>(ReceivedRoute.LEDGER_ID_ARGUMENT_NAME)!!.toLong()

private var envelope = Envelope()

fun getEnvelope() = viewModelScope.launch {
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, ReceivedEnvelopeEditSideEffect>(
ReceivedEnvelopeEditState(),
) {
private val argument = savedStateHandle.get<String>(ReceivedRoute.ENVELOPE_ARGUMENT_NAME)!!
private val ledgerId = savedStateHandle.get<String>(ReceivedRoute.LEDGER_ID_ARGUMENT_NAME)!!.toLong()

private var isFirstVisited: Boolean = true

Expand All @@ -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)

Expand All @@ -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)),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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"
}

0 comments on commit d638626

Please sign in to comment.