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 137 received envelope filter api #129

Merged
merged 11 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -68,12 +68,12 @@ fun SusuSearchBar(
decorationBox = { innerText ->
Row(
modifier = Modifier
.clip(RoundedCornerShape(4.dp))
.background(Gray20)
.padding(
horizontal = SusuTheme.spacing.spacing_m,
vertical = SusuTheme.spacing.spacing_xxs,
)
.clip(RoundedCornerShape(4.dp)),
),
verticalAlignment = Alignment.CenterVertically,
) {
Image(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.susu.core.model

data class EnvelopeFilterConfig(
val minReceivedAmount: Long,
val maxReceivedAmount: Long,
val minSentAmount: Long,
val maxSentAmount: Long,
)
1 change: 1 addition & 0 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ android {
}

dependencies {
implementation(projects.core.model)
implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlinx.immutable)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.susu.core.ui.argument

import com.susu.core.model.Friend
import kotlinx.serialization.Serializable

@Serializable
data class EnvelopeFilterArgument(
val selectedFriendList: List<Friend> = emptyList(),
val fromAmount: Long? = null,
val toAmount: Long? = null,
val isSent: Boolean = false,
)
5 changes: 5 additions & 0 deletions core/ui/src/main/java/com/susu/core/ui/extension/Long.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ fun Long.toMoneyFormat(): String {
// DecimalFormat์€ Thread Safeํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ง€์—ญ ๋ณ€์ˆ˜๋กœ ์‚ฌ์šฉํ•จ.
return DecimalFormat("#,###").format(this)
}

fun Float.toMoneyFormat(): String {
// DecimalFormat์€ Thread Safeํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ง€์—ญ ๋ณ€์ˆ˜๋กœ ์‚ฌ์šฉํ•จ.
return DecimalFormat("#,###").format(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.susu.data.data.repository

import com.susu.core.model.Envelope
import com.susu.core.model.EnvelopeDetail
import com.susu.core.model.EnvelopeFilterConfig
import com.susu.core.model.EnvelopeSearch
import com.susu.core.model.FriendStatistics
import com.susu.core.model.Relationship
Expand Down Expand Up @@ -150,6 +151,12 @@ class EnvelopesRepositoryImpl @Inject constructor(
),
).getOrThrow().toModel()

override suspend fun getEnvelopeFilterConfig(): EnvelopeFilterConfig =
envelopesService
.getEnvelopeFilterConfig()
.getOrThrow()
.toModel()

override suspend fun getEnvelopeDetail(
id: Long,
): EnvelopeDetail = envelopesService.getEnvelopeDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.susu.data.remote.api

import com.susu.data.remote.model.request.EnvelopeRequest
import com.susu.data.remote.model.response.EnvelopeDetailResponse
import com.susu.data.remote.model.response.EnvelopeFilterConfigResponse
import com.susu.data.remote.model.response.EnvelopeResponse
import com.susu.data.remote.model.response.EnvelopesHistoryListResponse
import com.susu.data.remote.model.response.EnvelopesListResponse
Expand Down Expand Up @@ -81,4 +82,7 @@ interface EnvelopesService {
@Query("size") size: Int?,
@Query("sort") sort: String?,
): ApiResult<SearchEnvelopeResponse>

@GET("envelopes/configs/search-filter")
suspend fun getEnvelopeFilterConfig(): ApiResult<EnvelopeFilterConfigResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.susu.data.remote.model.response

import com.susu.core.model.EnvelopeFilterConfig
import kotlinx.serialization.Serializable

@Serializable
data class EnvelopeFilterConfigResponse(
val minReceivedAmount: Long,
val maxReceivedAmount: Long,
val minSentAmount: Long,
val maxSentAmount: Long,
)

internal fun EnvelopeFilterConfigResponse.toModel() = EnvelopeFilterConfig(
minReceivedAmount = minReceivedAmount,
maxReceivedAmount = maxReceivedAmount,
minSentAmount = minSentAmount,
maxSentAmount = maxSentAmount,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.susu.domain.repository

import com.susu.core.model.Envelope
import com.susu.core.model.EnvelopeDetail
import com.susu.core.model.EnvelopeFilterConfig
import com.susu.core.model.EnvelopeSearch
import com.susu.core.model.FriendStatistics
import com.susu.core.model.Relationship
Expand Down Expand Up @@ -81,4 +82,6 @@ interface EnvelopesRepository {
categoryId: Long? = null,
customCategory: String? = null,
): Envelope

suspend fun getEnvelopeFilterConfig(): EnvelopeFilterConfig
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.susu.domain.usecase.envelope

import com.susu.core.common.runCatchingIgnoreCancelled
import com.susu.domain.repository.EnvelopesRepository
import javax.inject.Inject

class GetEnvelopeFilterConfigUseCase @Inject constructor(
private val envelopesRepository: EnvelopesRepository,
) {
suspend operator fun invoke() = runCatchingIgnoreCancelled {
envelopesRepository.getEnvelopeFilterConfig()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.susu.feature.mypage.navigation.navigateMyPageInfo
import com.susu.feature.mypage.navigation.navigateMyPagePrivacyPolicy
import com.susu.feature.mypage.navigation.navigateMyPageSocial
import com.susu.feature.received.navigation.ReceivedRoute
import com.susu.feature.received.navigation.argument.FilterArgument
import com.susu.feature.received.navigation.argument.LedgerFilterArgument
import com.susu.feature.received.navigation.navigateLedgerAdd
import com.susu.feature.received.navigation.navigateLedgerDetail
import com.susu.feature.received.navigation.navigateLedgerEdit
Expand All @@ -36,6 +36,7 @@ import com.susu.feature.received.navigation.navigateReceivedEnvelopeAdd
import com.susu.feature.received.navigation.navigateReceivedEnvelopeDetail
import com.susu.feature.received.navigation.navigateReceivedEnvelopeEdit
import com.susu.feature.sent.navigation.SentRoute
import com.susu.feature.sent.navigation.navigateEnvelopeFilter
import com.susu.feature.sent.navigation.navigateSent
import com.susu.feature.sent.navigation.navigateSentEnvelope
import com.susu.feature.sent.navigation.navigateSentEnvelopeAdd
Expand All @@ -62,9 +63,10 @@ internal class MainNavigator(
get() = when (currentDestination?.route) {
in listOf(
ReceivedRoute.ledgerSearchRoute,
ReceivedRoute.ledgerFilterRoute("{${ReceivedRoute.FILTER_ARGUMENT_NAME}}"),
ReceivedRoute.ledgerFilterRoute("{${ReceivedRoute.FILTER_LEDGER_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.envelopeFilterRoute("{${SentRoute.FILTER_ENVELOPE_ARGUMENT}}"),
SentRoute.sentEnvelopeRoute("{${SentRoute.FRIEND_ID_ARGUMENT_NAME}}"),
SentRoute.sentEnvelopeDetailRoute("{${SentRoute.ENVELOPE_ID_ARGUMENT_NAME}}"),
SentRoute.sentEnvelopeEditRoute("{${SentRoute.ENVELOPE_DETAIL_ARGUMENT_NAME}}"),
Expand Down Expand Up @@ -153,7 +155,7 @@ internal class MainNavigator(
navController.navigateLedgerEdit(ledger)
}

fun navigateLedgerFilter(filter: FilterArgument) {
fun navigateLedgerFilter(filter: LedgerFilterArgument) {
navController.navigateLedgerFilter(filter)
}

Expand Down Expand Up @@ -197,6 +199,10 @@ internal class MainNavigator(
navController.navigateVoteDetail(voteId)
}

fun navigateEnvelopeFilter(filter: String) {
navController.navigateEnvelopeFilter(filter)
}

fun navigateVoteEdit(vote: Vote) {
navController.navigateVoteEdit(vote)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.susu.feature.loginsignup.navigation.loginSignupNavGraph
import com.susu.feature.mypage.navigation.myPageNavGraph
import com.susu.feature.received.navigation.ReceivedRoute
import com.susu.feature.received.navigation.receivedNavGraph
import com.susu.feature.sent.navigation.SentRoute
import com.susu.feature.sent.navigation.sentNavGraph
import com.susu.feature.statistics.navigation.statisticsNavGraph
import kotlinx.collections.immutable.ImmutableList
Expand Down Expand Up @@ -84,6 +85,13 @@ internal fun MainScreen(
navigateSentEnvelopeDetail = navigator::navigateSentEnvelopeDetail,
navigateSentEnvelopeEdit = navigator::navigateSentEnvelopeEdit,
navigateSentEnvelopeAdd = navigator::navigateSentEnvelopeAdd,
popBackStackWithFilter = { filter ->
navigator.navController.previousBackStackEntry?.savedStateHandle?.set(
SentRoute.FILTER_ENVELOPE_ARGUMENT,
filter,
)
navigator.popBackStackIfNotHome()
},
navigateSentEnvelopeSearch = navigator::navigateSentEnvelopeSearch,
handleException = viewModel::handleException,
onShowSnackbar = viewModel::onShowSnackbar,
Expand All @@ -92,6 +100,7 @@ internal fun MainScreen(

receivedNavGraph(
padding = innerPadding,
envelopeFilterArgumentName = SentRoute.FILTER_ENVELOPE_ARGUMENT,
popBackStack = navigator::popBackStackIfNotHome,
popBackStackWithLedger = { ledger ->
navigator.navController.previousBackStackEntry?.savedStateHandle?.set(
Expand All @@ -109,7 +118,7 @@ internal fun MainScreen(
},
popBackStackWithFilter = { filter ->
navigator.navController.previousBackStackEntry?.savedStateHandle?.set(
ReceivedRoute.FILTER_ARGUMENT_NAME,
ReceivedRoute.FILTER_LEDGER_ARGUMENT_NAME,
filter,
)
navigator.popBackStackIfNotHome()
Expand All @@ -136,6 +145,7 @@ internal fun MainScreen(
navigateEnvelopAdd = navigator::navigateReceivedEnvelopeAdd,
navigateEnvelopeDetail = navigator::navigateReceivedEnvelopeDetail,
navigateEnvelopeEdit = navigator::navigateReceivedEnvelopeEdit,
navigateEnvelopeFilter = navigator::navigateEnvelopeFilter,
onShowSnackbar = viewModel::onShowSnackbar,
onShowDialog = viewModel::onShowDialog,
handleException = viewModel::handleException,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.susu.feature.received.ledgerdetail

import androidx.annotation.StringRes
import com.susu.core.model.Envelope
import com.susu.core.model.Friend
import com.susu.core.model.Ledger
import com.susu.core.model.SearchEnvelope
import com.susu.core.ui.R
import com.susu.core.ui.base.SideEffect
import com.susu.core.ui.base.UiState
import kotlinx.collections.immutable.PersistentList
Expand All @@ -16,7 +19,36 @@ data class LedgerDetailState(
val startDate: String = "",
val endDate: String = "",
val envelopeList: PersistentList<SearchEnvelope> = persistentListOf(),
) : UiState
val selectedFriendList: PersistentList<Friend> = persistentListOf(),
val fromAmount: Long? = null,
val toAmount: Long? = null,
val showAlignBottomSheet: Boolean = false,
val selectedAlignPosition: Int = EnvelopeAlign.RECENT.ordinal,
) : UiState {
val isFiltered = fromAmount != null || toAmount != null || selectedFriendList.isNotEmpty()
}

enum class EnvelopeAlign(
@StringRes val stringResId: Int,
val query: String,
) {
RECENT(
stringResId = R.string.word_align_recently,
query = "createdAt,desc",
),
OUTDATED(
stringResId = R.string.word_align_outdated,
query = "createdAt,asc",
),
HIGH_AMOUNT(
stringResId = R.string.word_align_high_amount,
query = "totalReceivedAmounts,desc",
),
LOW_AMOUNT(
stringResId = R.string.word_align_low_amount,
query = "totalReceivedAmounts,asc",
),
}

sealed interface LedgerDetailSideEffect : SideEffect {
data class NavigateEnvelopeAdd(val ledger: Ledger) : LedgerDetailSideEffect
Expand All @@ -28,4 +60,5 @@ sealed interface LedgerDetailSideEffect : SideEffect {
data object ShowDeleteSuccessSnackbar : LedgerDetailSideEffect
data class ShowSnackbar(val msg: String) : LedgerDetailSideEffect
data class HandleException(val throwable: Throwable, val retry: () -> Unit) : LedgerDetailSideEffect
data class NavigateEnvelopeFilter(val filter: String) : LedgerDetailSideEffect
}
Loading
Loading