Skip to content
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

Feature/mz 182 ledger add #79

Merged
merged 15 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ fun SusuDatePickerBottomSheet(
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SusuLimitDatePickerBottomSheet(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ°”ν…€μ‹œνŠΈμ—μ„œ λ¦¬μŠ€νŠΈμ— λ³΄μ΄λŠ” λ‚ μ§œλ₯Ό λˆŒλŸ¬μ„œλ„ 선택할 수 μžˆλ„λ‘ μˆ˜μ •ν•΄μ•Ό ν•  것 κ°™λ”λΌκ³ μš”..
ν•„μˆ˜ 피쳐 λΉ¨λž‘ 끝내고 좔가해보렀고 ν•©λ‹ˆλ‹€~

criteriaYear: Int,
criteriaMonth: Int,
criteriaDay: Int,
initialCriteriaYear: Int? = null,
initialCriteriaMonth: Int? = null,
initialCriteriaDay: Int? = null,
initialYear: Int? = null,
initialMonth: Int? = null,
initialDay: Int? = null,
Expand All @@ -130,6 +130,12 @@ fun SusuLimitDatePickerBottomSheet(
onDismissRequest: (Int, Int, Int) -> Unit = { _, _, _ -> },
onItemSelected: (Int, Int, Int) -> Unit = { _, _, _ -> },
) {
val (criteriaYear, criteriaMonth, criteriaDay) = listOf(
initialCriteriaYear ?: 2030,
initialCriteriaMonth ?: 12,
initialCriteriaDay ?: 31,
)

var selectedYear by remember {
mutableIntStateOf(
when {
Expand Down Expand Up @@ -273,6 +279,7 @@ fun SusuLimitDatePickerBottomSheet(
)
} else {
selectedDay = criteriaDay
onItemSelected(selectedYear, selectedMonth, selectedDay)
Box(
modifier = Modifier
.width(100.dp)
Expand Down Expand Up @@ -348,9 +355,9 @@ private fun getLastDayInMonth(year: Int, month: Int): Int {
fun SusuLimitDatePickerBottomSheetPreview() {
SusuTheme {
SusuLimitDatePickerBottomSheet(
criteriaYear = 2024,
criteriaMonth = 2,
criteriaDay = 16,
initialCriteriaYear = 2024,
initialCriteriaMonth = 2,
initialCriteriaDay = 16,
initialYear = 2024,
initialMonth = 2,
initialDay = 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fun BasicButton(
rightIcon: (@Composable () -> Unit)? = null,
iconSpacing: Dp = 0.dp,
isClickable: Boolean = true,
rippleEnabled: Boolean = true,
onClick: () -> Unit = {},
) {
Box(
Expand All @@ -52,6 +53,7 @@ fun BasicButton(
shape = shape,
)
.susuClickable(
rippleEnabled = rippleEnabled,
rippleColor = rippleColor,
runIf = isClickable,
onClick = onClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fun SusuGhostButton(
rightIcon: (@Composable () -> Unit)? = null,
isActive: Boolean = true,
isClickable: Boolean = true,
rippleEnabled: Boolean = true,
onClick: () -> Unit = {},
) {
val (paddingValues, iconSpacing, textStyle) = style()
Expand All @@ -73,6 +74,7 @@ fun SusuGhostButton(
padding = paddingValues,
iconSpacing = iconSpacing,
isClickable = isClickable,
rippleEnabled = rippleEnabled,
onClick = onClick,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fun SusuTextFieldFillMaxButton(
onClickCloseIcon: () -> Unit = {},
onClickFilledButton: () -> Unit = {},
onClickButton: (isFocused: Boolean) -> Unit = {},
focusRequester: FocusRequester = remember { FocusRequester() },
) {
val (backgroundColor, textColor) = with(color) {
when {
Expand All @@ -88,7 +89,8 @@ fun SusuTextFieldFillMaxButton(
BasicTextField(
modifier = modifier
.fillMaxWidth()
.susuClickable { onClickButton(isFocused) },
.susuClickable { onClickButton(isFocused) }
.focusRequester(focusRequester),
value = text,
onValueChange = onTextChange,
enabled = isSaved.not() && isFocused,
Expand Down
12 changes: 11 additions & 1 deletion core/ui/src/main/java/com/susu/core/ui/util/Date.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package com.susu.core.ui.util

import android.util.Log
import java.time.DateTimeException
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

val currentDate = LocalDateTime.now()
val currentDate: LocalDateTime = LocalDateTime.now()
val minDate: LocalDateTime = LocalDateTime.of(1930, 1, 1, 0, 0)

@Suppress("detekt:FunctionNaming")
fun LocalDateTime.to_yyyy_dot_MM_dot_dd(): String {
val formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd")
return this.format(formatter)
}

fun getSafeLocalDateTime(year: Int, month: Int, day: Int): LocalDateTime = try {
LocalDateTime.of(year, month, day, 0, 0)
} catch (e: DateTimeException) {
Log.e("DateTimeError", "Invalid date provided: $year-$month-$day", e)
LocalDateTime.of(year, month, 1, 0, 0)
}
1 change: 1 addition & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<string name="word_next">λ‹€μŒ</string>
<string name="word_done">μ™„λ£Œ</string>
<string name="word_apply_filter">ν•„ν„° μ μš©ν•˜κΈ°</string>
<string name="word_input_placeholder">μž…λ ₯ν•΄μ£Όμ„Έμš”</string>
<string name="sns_kakao">μΉ΄μΉ΄μ˜€ν†‘</string>
<string name="sns_naver">넀이버</string>
<string name="sns_google">ꡬ글</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class LedgerRepositoryImpl @Inject constructor(
sort = sort,
).getOrThrow().toModel()

override suspend fun createLedger(ledger: Ledger): Ledger = ledgerService.createLedger(
ledgerRequest = ledger.toData(),
).getOrThrow().toModel()

override suspend fun editLedger(ledger: Ledger): Ledger = ledgerService.editLedger(
id = ledger.id,
ledgerRequest = ledger.toData(),
Expand Down
6 changes: 6 additions & 0 deletions data/src/main/java/com/susu/data/remote/api/LedgerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

Expand All @@ -29,6 +30,11 @@ interface LedgerService {
@Body ledgerRequest: LedgerRequest,
): ApiResult<LedgerResponse>

@POST("ledgers")
suspend fun createLedger(
@Body ledgerRequest: LedgerRequest,
): ApiResult<LedgerResponse>

@DELETE("ledgers")
suspend fun deleteLedgerList(@Query("ids") idList: List<Int>): ApiResult<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ interface LedgerRepository {
sort: String?,
): List<Ledger>

suspend fun createLedger(
ledger: Ledger,
): Ledger

suspend fun editLedger(
ledger: Ledger,
): Ledger
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.susu.domain.usecase.ledger

import com.susu.core.common.runCatchingIgnoreCancelled
import com.susu.core.model.Ledger
import com.susu.domain.repository.LedgerRepository
import javax.inject.Inject

class CreateLedgerUseCase @Inject constructor(
private val ledgerRepository: LedgerRepository,
) {
suspend operator fun invoke(ledger: Ledger) = runCatchingIgnoreCancelled {
ledgerRepository.createLedger(ledger)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.susu.feature.received.ledgeradd

import com.susu.core.ui.base.SideEffect
import com.susu.core.ui.base.UiState

data class LedgerAddState(
val currentStep: LedgerAddStep = LedgerAddStep.CATEGORY,
val buttonEnabled: Boolean = false,
val isLoading: Boolean = false,
) : UiState

enum class LedgerAddStep {
CATEGORY,
NAME,
DATE,
}

sealed interface LedgerAddSideEffect : SideEffect {
data object PopBackStack : LedgerAddSideEffect
data class PopBackStackWithLedger(val ledger: String) : LedgerAddSideEffect
data class HandleException(val throwable: Throwable, val retry: () -> Unit) : LedgerAddSideEffect
}
Loading