From 978d6089df77b11c68f2c6dc0658ee6679782098 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Fri, 26 Jan 2024 14:26:53 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20GetCreateLedgerConfigUseCase=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/data/repository/LedgerRepositoryImpl.kt | 2 ++ .../com/susu/data/remote/api/LedgerService.kt | 4 ++++ .../model/response/CreateLedgerConfigResponse.kt | 5 +++++ .../susu/domain/repository/LedgerRepository.kt | 2 ++ .../ledger/GetCreateLedgerConfigUseCase.kt | 16 ++++++++++++++++ 5 files changed, 29 insertions(+) create mode 100644 data/src/main/java/com/susu/data/remote/model/response/CreateLedgerConfigResponse.kt create mode 100644 domain/src/main/java/com/susu/domain/usecase/ledger/GetCreateLedgerConfigUseCase.kt diff --git a/data/src/main/java/com/susu/data/data/repository/LedgerRepositoryImpl.kt b/data/src/main/java/com/susu/data/data/repository/LedgerRepositoryImpl.kt index 4ea4bfd5..3093801a 100644 --- a/data/src/main/java/com/susu/data/data/repository/LedgerRepositoryImpl.kt +++ b/data/src/main/java/com/susu/data/data/repository/LedgerRepositoryImpl.kt @@ -40,4 +40,6 @@ class LedgerRepositoryImpl @Inject constructor( override suspend fun deleteLedger(id: Int) = ledgerService.deleteLedgerList( listOf(id), ).getOrThrow() + + override suspend fun getCreateLedgerConfig(): List = ledgerService.getCreateLedgerConfig().getOrThrow().onlyStartAtCategoryIds } diff --git a/data/src/main/java/com/susu/data/remote/api/LedgerService.kt b/data/src/main/java/com/susu/data/remote/api/LedgerService.kt index 08b9ea12..a880d175 100644 --- a/data/src/main/java/com/susu/data/remote/api/LedgerService.kt +++ b/data/src/main/java/com/susu/data/remote/api/LedgerService.kt @@ -1,6 +1,7 @@ package com.susu.data.remote.api import com.susu.data.remote.model.request.LedgerRequest +import com.susu.data.remote.model.response.CreateLedgerConfigResponse import com.susu.data.remote.model.response.LedgerListResponse import com.susu.data.remote.model.response.LedgerResponse import com.susu.data.remote.retrofit.ApiResult @@ -37,4 +38,7 @@ interface LedgerService { @DELETE("ledgers") suspend fun deleteLedgerList(@Query("ids") idList: List): ApiResult + + @GET("ledgers/configs/create-ledger") + suspend fun getCreateLedgerConfig(): ApiResult } diff --git a/data/src/main/java/com/susu/data/remote/model/response/CreateLedgerConfigResponse.kt b/data/src/main/java/com/susu/data/remote/model/response/CreateLedgerConfigResponse.kt new file mode 100644 index 00000000..9bfb6c14 --- /dev/null +++ b/data/src/main/java/com/susu/data/remote/model/response/CreateLedgerConfigResponse.kt @@ -0,0 +1,5 @@ +package com.susu.data.remote.model.response + +data class CreateLedgerConfigResponse( + val onlyStartAtCategoryIds: List, +) diff --git a/domain/src/main/java/com/susu/domain/repository/LedgerRepository.kt b/domain/src/main/java/com/susu/domain/repository/LedgerRepository.kt index 96926852..eca4dec3 100644 --- a/domain/src/main/java/com/susu/domain/repository/LedgerRepository.kt +++ b/domain/src/main/java/com/susu/domain/repository/LedgerRepository.kt @@ -24,4 +24,6 @@ interface LedgerRepository { suspend fun deleteLedger( id: Int, ) + + suspend fun getCreateLedgerConfig(): List } diff --git a/domain/src/main/java/com/susu/domain/usecase/ledger/GetCreateLedgerConfigUseCase.kt b/domain/src/main/java/com/susu/domain/usecase/ledger/GetCreateLedgerConfigUseCase.kt new file mode 100644 index 00000000..88a26f8d --- /dev/null +++ b/domain/src/main/java/com/susu/domain/usecase/ledger/GetCreateLedgerConfigUseCase.kt @@ -0,0 +1,16 @@ +package com.susu.domain.usecase.ledger + +import com.susu.core.common.runCatchingIgnoreCancelled +import com.susu.domain.repository.LedgerRepository +import java.time.LocalDateTime +import javax.inject.Inject + +typealias OnlyStartAtCategoryIdList = List + +class GetCreateLedgerConfigUseCase @Inject constructor( + private val ledgerRepository: LedgerRepository, +) { + suspend operator fun invoke(): Result = runCatchingIgnoreCancelled { + ledgerRepository.getCreateLedgerConfig() + } +} From b9517124640aa1450834fb5c497e9a2d2fef2770 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Fri, 26 Jan 2024 15:10:12 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EC=9E=A5=EB=B6=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EC=8B=9C,=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EC=8B=9C=EC=9E=91=EC=9D=BC?= =?UTF-8?q?=EB=A7=8C=20=EB=B3=B4=EC=9D=B4=EA=B2=8C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/CreateLedgerConfigResponse.kt | 3 ++ .../received/ledgeradd/LedgerAddScreen.kt | 12 +++--- .../ledgeradd/content/date/DateContent.kt | 42 +++++++++++++----- .../ledgeradd/content/date/DateContract.kt | 1 + .../ledgeradd/content/date/DateViewModel.kt | 43 ++++++++++++++++--- .../received/src/main/res/values/strings.xml | 2 + 6 files changed, 81 insertions(+), 22 deletions(-) diff --git a/data/src/main/java/com/susu/data/remote/model/response/CreateLedgerConfigResponse.kt b/data/src/main/java/com/susu/data/remote/model/response/CreateLedgerConfigResponse.kt index 9bfb6c14..841aa418 100644 --- a/data/src/main/java/com/susu/data/remote/model/response/CreateLedgerConfigResponse.kt +++ b/data/src/main/java/com/susu/data/remote/model/response/CreateLedgerConfigResponse.kt @@ -1,5 +1,8 @@ package com.susu.data.remote.model.response +import kotlinx.serialization.Serializable + +@Serializable data class CreateLedgerConfigResponse( val onlyStartAtCategoryIds: List, ) diff --git a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/LedgerAddScreen.kt b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/LedgerAddScreen.kt index 61f261ec..b3b2a2ab 100644 --- a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/LedgerAddScreen.kt +++ b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/LedgerAddScreen.kt @@ -51,8 +51,8 @@ fun LedgerAddRoute( } } - var dateContentCategoryName: String by remember { - mutableStateOf("") + var dateContentCategory: Category? by remember { + mutableStateOf(null) } var dateContentName: String by remember { @@ -69,14 +69,14 @@ fun LedgerAddRoute( onClickNextButton = viewModel::goToNextStep, updateParentSelectedCategory = { category -> viewModel.updateSelectedCategory(category) - dateContentCategoryName = category?.customCategory ?: category?.name ?: "" + dateContentCategory = category }, updateParentName = { name -> viewModel.updateName(name) dateContentName = name }, dateContentName = dateContentName, - dateContentCategoryName = dateContentCategoryName, + dateContentCategory = dateContentCategory, updateParentDate = { startAt, endAt -> viewModel.updateDate(startAt, endAt) }, @@ -90,7 +90,7 @@ fun LedgerAddScreen( onClickNextButton: () -> Unit = {}, updateParentSelectedCategory: (Category?) -> Unit = {}, updateParentName: (String) -> Unit = {}, - dateContentCategoryName: String = "", + dateContentCategory: Category? = Category(), dateContentName: String = "", updateParentDate: (LocalDateTime?, LocalDateTime?) -> Unit = { _, _ -> }, ) { @@ -129,7 +129,7 @@ fun LedgerAddScreen( LedgerAddStep.DATE -> DateContentRoute( name = dateContentName, - categoryName = dateContentCategoryName, + category = dateContentCategory, updateParentDate = updateParentDate, ) } diff --git a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContent.kt b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContent.kt index c992de57..898e2ede 100644 --- a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContent.kt +++ b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContent.kt @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview @@ -15,8 +16,12 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.susu.core.designsystem.component.bottomsheet.datepicker.SusuLimitDatePickerBottomSheet +import com.susu.core.designsystem.component.button.GhostButtonColor +import com.susu.core.designsystem.component.button.SmallButtonStyle +import com.susu.core.designsystem.component.button.SusuGhostButton import com.susu.core.designsystem.theme.Gray60 import com.susu.core.designsystem.theme.SusuTheme +import com.susu.core.model.Category import com.susu.core.ui.extension.collectWithLifecycle import com.susu.core.ui.util.AnnotatedText import com.susu.core.ui.util.currentDate @@ -29,7 +34,7 @@ import java.time.LocalDateTime fun DateContentRoute( viewModel: DateViewModel = hiltViewModel(), name: String, - categoryName: String, + category: Category?, updateParentDate: (LocalDateTime?, LocalDateTime?) -> Unit, ) { val uiState = viewModel.uiState.collectAsStateWithLifecycle().value @@ -44,7 +49,8 @@ fun DateContentRoute( } LaunchedEffect(key1 = Unit) { - viewModel.updateNameAndCategory(name, categoryName) + viewModel.setScreenType(category ?: Category()) + viewModel.updateNameAndCategory(name, category?.customCategory ?: category?.name ?: "") } DateContent( @@ -55,6 +61,7 @@ fun DateContentRoute( onEndDateItemSelected = viewModel::updateEndDate, onClickEndDateText = viewModel::showEndDateBottomSheet, onDismissEndDateBottomSheet = viewModel::hideEndDateBottomSheet, + onClickSetDateButton = viewModel::toggleShowOnlyStartAt, ) } @@ -68,6 +75,7 @@ fun DateContent( onEndDateItemSelected: (Int, Int, Int) -> Unit = { _, _, _ -> }, onClickEndDateText: () -> Unit = {}, onDismissEndDateBottomSheet: () -> Unit = {}, + onClickSetDateButton: () -> Unit = {}, ) { Column( modifier = Modifier @@ -93,19 +101,33 @@ fun DateContent( year = uiState.startAt?.year, month = uiState.startAt?.monthValue, day = uiState.startAt?.dayOfMonth, - suffix = stringResource(R.string.ledger_add_screen_from), + suffix = if(uiState.showOnlyStartAt.not()) stringResource(R.string.ledger_add_screen_from) else "", onClick = onClickStartDateText, ) - Spacer(modifier = Modifier.size(SusuTheme.spacing.spacing_xxs)) + if (uiState.showOnlyStartAt.not()) { + Spacer(modifier = Modifier.size(SusuTheme.spacing.spacing_xxs)) - SelectDateRow( - year = uiState.endAt?.year, - month = uiState.endAt?.monthValue, - day = uiState.endAt?.dayOfMonth, - suffix = stringResource(R.string.ledger_add_screen_until), - onClick = onClickEndDateText, + SelectDateRow( + year = uiState.endAt?.year, + month = uiState.endAt?.monthValue, + day = uiState.endAt?.dayOfMonth, + suffix = stringResource(R.string.ledger_add_screen_until), + onClick = onClickEndDateText, + ) + } + + Spacer(modifier = Modifier.weight(1f)) + + SusuGhostButton( + modifier = Modifier.align(Alignment.CenterHorizontally), + color = GhostButtonColor.Orange, + style = SmallButtonStyle.height40, + text = if(uiState.showOnlyStartAt) stringResource(R.string.date_content_show_endat) else stringResource(R.string.date_content_set_only_startat), + onClick = onClickSetDateButton, ) + + Spacer(modifier = Modifier.size(SusuTheme.spacing.spacing_xxl)) } if (uiState.showStartDateBottomSheet) { diff --git a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContract.kt b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContract.kt index 6385f37d..67bc5ab1 100644 --- a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContract.kt +++ b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContract.kt @@ -12,6 +12,7 @@ data class DateState( val endAt: LocalDateTime? = null, val showStartDateBottomSheet: Boolean = false, val showEndDateBottomSheet: Boolean = false, + val showOnlyStartAt: Boolean = false, ) : UiState sealed interface DateSideEffect : SideEffect { diff --git a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateViewModel.kt b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateViewModel.kt index c64ac824..5d59ef16 100644 --- a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateViewModel.kt +++ b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateViewModel.kt @@ -1,15 +1,33 @@ package com.susu.feature.received.ledgeradd.content.date +import androidx.lifecycle.viewModelScope +import com.susu.core.model.Category import com.susu.core.ui.base.BaseViewModel import com.susu.core.ui.util.getSafeLocalDateTime +import com.susu.domain.usecase.ledger.GetCreateLedgerConfigUseCase import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import timber.log.Timber import java.time.LocalDateTime import javax.inject.Inject @HiltViewModel -class DateViewModel @Inject constructor() : BaseViewModel( +class DateViewModel @Inject constructor( + private val getCreateLedgerConfigUseCase: GetCreateLedgerConfigUseCase, +) : BaseViewModel( DateState(), ) { + private var category = Category() + + fun setScreenType(category: Category) = viewModelScope.launch { + if (this@DateViewModel.category == category) return@launch + + getCreateLedgerConfigUseCase() + .onSuccess { onlyStartAtCategoryIdList -> + intent { copy(showOnlyStartAt = category.id in onlyStartAtCategoryIdList) } + } + } + fun updateNameAndCategory(name: String, categoryName: String) = intent { copy( name = name, @@ -19,9 +37,11 @@ class DateViewModel @Inject constructor() : BaseViewModel한끼 식사 01012345678 입력해주세요 + 종료일 추가 + 시작일만 지정 From 0d458dee769d66e5a71254921a65e8c9c8eae903 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Fri, 26 Jan 2024 15:10:54 +0900 Subject: [PATCH 3/3] chore: ktlint, detekt --- .../usecase/ledger/GetCreateLedgerConfigUseCase.kt | 1 - .../received/ledgeradd/content/date/DateContent.kt | 10 ++++++++-- .../received/ledgeradd/content/date/DateViewModel.kt | 5 ++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/domain/src/main/java/com/susu/domain/usecase/ledger/GetCreateLedgerConfigUseCase.kt b/domain/src/main/java/com/susu/domain/usecase/ledger/GetCreateLedgerConfigUseCase.kt index 88a26f8d..b0b22f34 100644 --- a/domain/src/main/java/com/susu/domain/usecase/ledger/GetCreateLedgerConfigUseCase.kt +++ b/domain/src/main/java/com/susu/domain/usecase/ledger/GetCreateLedgerConfigUseCase.kt @@ -2,7 +2,6 @@ package com.susu.domain.usecase.ledger import com.susu.core.common.runCatchingIgnoreCancelled import com.susu.domain.repository.LedgerRepository -import java.time.LocalDateTime import javax.inject.Inject typealias OnlyStartAtCategoryIdList = List diff --git a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContent.kt b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContent.kt index 898e2ede..b5be883f 100644 --- a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContent.kt +++ b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateContent.kt @@ -101,7 +101,7 @@ fun DateContent( year = uiState.startAt?.year, month = uiState.startAt?.monthValue, day = uiState.startAt?.dayOfMonth, - suffix = if(uiState.showOnlyStartAt.not()) stringResource(R.string.ledger_add_screen_from) else "", + suffix = if (uiState.showOnlyStartAt.not()) stringResource(R.string.ledger_add_screen_from) else "", onClick = onClickStartDateText, ) @@ -123,7 +123,13 @@ fun DateContent( modifier = Modifier.align(Alignment.CenterHorizontally), color = GhostButtonColor.Orange, style = SmallButtonStyle.height40, - text = if(uiState.showOnlyStartAt) stringResource(R.string.date_content_show_endat) else stringResource(R.string.date_content_set_only_startat), + text = if (uiState.showOnlyStartAt) { + stringResource(R.string.date_content_show_endat) + } else { + stringResource( + R.string.date_content_set_only_startat, + ) + }, onClick = onClickSetDateButton, ) diff --git a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateViewModel.kt b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateViewModel.kt index 5d59ef16..115ceece 100644 --- a/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateViewModel.kt +++ b/feature/received/src/main/java/com/susu/feature/received/ledgeradd/content/date/DateViewModel.kt @@ -7,7 +7,6 @@ import com.susu.core.ui.util.getSafeLocalDateTime import com.susu.domain.usecase.ledger.GetCreateLedgerConfigUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch -import timber.log.Timber import java.time.LocalDateTime import javax.inject.Inject @@ -62,13 +61,13 @@ class DateViewModel @Inject constructor( postSideEffect(DateSideEffect.UpdateParentDate(startAt, null)) copy( showOnlyStartAt = false, - endAt = null + endAt = null, ) } else { postSideEffect(DateSideEffect.UpdateParentDate(startAt, startAt)) copy( showOnlyStartAt = true, - endAt = startAt + endAt = startAt, ) } }