Skip to content

Commit

Permalink
[Feature] History 파일구조 변경 (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajou4095 authored Feb 5, 2024
1 parent 85f0798 commit b8d1023
Show file tree
Hide file tree
Showing 27 changed files with 200 additions and 255 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ac.dnd.bookkeeping.android.domain.model.feature.group

import ac.dnd.bookkeeping.android.domain.model.feature.relation.RelationDetail

data class GroupWithRelationDetail(
val id: Long,
val name: String,
val relationList: List<RelationDetail>
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ac.dnd.bookkeeping.android.domain.model.feature.group

import ac.dnd.bookkeeping.android.domain.model.feature.relation.RelationSimple

data class GroupWithRelation(
data class GroupWithRelationSimple(
val id: Long,
val name: String,
val relationList: List<RelationSimple>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ac.dnd.bookkeeping.android.domain.usecase.feature.group

import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelationDetail
import ac.dnd.bookkeeping.android.domain.model.feature.relation.RelationDetail
import ac.dnd.bookkeeping.android.domain.model.feature.relation.RelationDetailGroup
import ac.dnd.bookkeeping.android.domain.usecase.feature.heart.GetHeartListUseCase
import javax.inject.Inject

class GetGroupHeartHistoryUseCase @Inject constructor(
private val getHeartListUseCase: GetHeartListUseCase
) {
suspend operator fun invoke(): Result<List<GroupWithRelationDetail>> {
return getHeartListUseCase("", "").map { heartList ->
heartList.groupBy { heart ->
heart.relation.group.id
}.map { (key, heartList) ->
val groupId = heartList.first().relation.group.id
val groupName = heartList.first().relation.group.name
GroupWithRelationDetail(
id = groupId,
name = groupName,
relationList = heartList.map { heart ->
RelationDetail(
id = heart.relation.id,
name = heart.relation.name,
group = RelationDetailGroup(
id = heart.relation.group.id,
name = heart.relation.group.name
),
giveMoney = heart.giveHistories.sum(),
takeMoney = heart.takeHistories.sum()
)
}
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package ac.dnd.bookkeeping.android.domain.usecase.feature.group

import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelation
import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelationSimple
import ac.dnd.bookkeeping.android.domain.usecase.feature.relation.GetRelationListUseCase
import javax.inject.Inject

class GetGroupListWithRelationUseCase @Inject constructor(
class GetGroupListWithRelationSimpleUseCase @Inject constructor(
private val getRelationListUseCase: GetRelationListUseCase
) {
suspend operator fun invoke(): Result<List<GroupWithRelation>> {
suspend operator fun invoke(): Result<List<GroupWithRelationSimple>> {
return getRelationListUseCase("").map { relationList ->
relationList.groupBy {
it.group.id
}.map { (_, relationList) ->
val group = relationList.first().group
GroupWithRelation(
GroupWithRelationSimple(
id = group.id,
name = group.name,
relationList = relationList
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ac.dnd.bookkeeping.android.presentation.common.view.chip

import ac.dnd.bookkeeping.android.domain.model.legacy.GroupLegacy
import ac.dnd.bookkeeping.android.domain.model.legacy.RelationLegacy
import ac.dnd.bookkeeping.android.domain.model.legacy.RelationGroupLegacy
import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelationDetail
import ac.dnd.bookkeeping.android.domain.model.feature.relation.RelationDetail
import ac.dnd.bookkeeping.android.domain.model.feature.relation.RelationDetailGroup
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
Expand All @@ -14,8 +14,8 @@ import androidx.compose.ui.unit.dp
fun GroupChipListComponent(
chipType: ChipType = ChipType.LESS_BORDER,
currentSelectedId: Long,
onSelectChip: (GroupLegacy) -> Unit,
groups : List<GroupLegacy>
onSelectChip: (GroupWithRelationDetail) -> Unit,
groups: List<GroupWithRelationDetail>
) {
LazyRow(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
items(groups) { group ->
Expand All @@ -24,7 +24,7 @@ fun GroupChipListComponent(
currentSelectedId = setOf(currentSelectedId),
chipId = group.id,
chipText = group.name,
chipCount = group.relations.size,
chipCount = group.relationList.size,
onSelectChip = {
onSelectChip(group)
}
Expand All @@ -41,14 +41,14 @@ fun GroupChipPreview() {
currentSelectedId = 0,
onSelectChip = {},
groups = listOf(
GroupLegacy(
GroupWithRelationDetail(
0,
"전체",
relations = listOf(
RelationLegacy(
relationList = listOf(
RelationDetail(
id = 3679,
name = "Jerome Pitts",
group = RelationGroupLegacy(
group = RelationDetailGroup(
id = 6599,
name = "Andrea Serrano",
),
Expand All @@ -57,14 +57,14 @@ fun GroupChipPreview() {
)
)
),
GroupLegacy(
GroupWithRelationDetail(
1,
"친구",
relations = listOf(
RelationLegacy(
relationList = listOf(
RelationDetail(
id = 3679,
name = "Jerome Pitts",
group = RelationGroupLegacy(
group = RelationDetailGroup(
id = 6599,
name = "Andrea Serrano",
),
Expand All @@ -73,7 +73,7 @@ fun GroupChipPreview() {
)
)
),
GroupLegacy(
GroupWithRelationDetail(
2,
"가족",
listOf()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.history.registration.type
package ac.dnd.bookkeeping.android.presentation.model.history

enum class HistoryRegistrationEventType(
val id: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.history.registration.type
package ac.dnd.bookkeeping.android.presentation.model.history

enum class HistoryRegistrationTagType(
val id: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.history.registration.type
package ac.dnd.bookkeeping.android.presentation.model.history

enum class HistoryRegistrationType(
val typeName: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.history.item.type
package ac.dnd.bookkeeping.android.presentation.model.history

enum class HistorySortedType(
val typeName: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.history.item.type
package ac.dnd.bookkeeping.android.presentation.model.history

enum class HistoryViewType(
val typeName: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.history.registration.calendar
package ac.dnd.bookkeeping.android.presentation.ui.main.common.calendar

import ac.dnd.bookkeeping.android.presentation.R
import ac.dnd.bookkeeping.android.presentation.common.theme.Gray000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.common.relation.get

import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelation
import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelationSimple
import androidx.compose.runtime.Immutable

@Immutable
data class GetRelationModel(
val state: GetRelationState,
val groups: List<GroupWithRelation>
val groups: List<GroupWithRelationSimple>
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.common.relation.get

import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelation
import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelationSimple
import ac.dnd.bookkeeping.android.domain.model.feature.relation.RelationSimple
import ac.dnd.bookkeeping.android.presentation.R
import ac.dnd.bookkeeping.android.presentation.common.theme.Body0
Expand Down Expand Up @@ -226,7 +226,7 @@ private fun SearchRelationScreen(
@Composable
@OptIn(ExperimentalMaterialApi::class)
private fun SearchRelationGroup(
group: GroupWithRelation,
group: GroupWithRelationSimple,
selectedRelation: RelationSimple?,
isExpanded: Boolean,
onExpandRequest: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.common.relation.get

import ac.dnd.bookkeeping.android.domain.model.error.ServerException
import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelation
import ac.dnd.bookkeeping.android.domain.usecase.feature.group.GetGroupListWithRelationUseCase
import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelationSimple
import ac.dnd.bookkeeping.android.domain.usecase.feature.group.GetGroupListWithRelationSimpleUseCase
import ac.dnd.bookkeeping.android.presentation.common.base.BaseViewModel
import ac.dnd.bookkeeping.android.presentation.common.base.ErrorEvent
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.EventFlow
Expand All @@ -18,7 +18,7 @@ import javax.inject.Inject
@HiltViewModel
class GetRelationViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle,
private val getGroupListWithRelationUseCase: GetGroupListWithRelationUseCase
private val getGroupListWithRelationSimpleUseCase: GetGroupListWithRelationSimpleUseCase
) : BaseViewModel() {

private val _state: MutableStateFlow<GetRelationState> =
Expand All @@ -28,13 +28,13 @@ class GetRelationViewModel @Inject constructor(
private val _event: MutableEventFlow<GetRelationEvent> = MutableEventFlow()
val event: EventFlow<GetRelationEvent> = _event.asEventFlow()

private val _groups: MutableStateFlow<List<GroupWithRelation>> = MutableStateFlow(emptyList())
val groups: StateFlow<List<GroupWithRelation>> = _groups.asStateFlow()
private val _groups: MutableStateFlow<List<GroupWithRelationSimple>> = MutableStateFlow(emptyList())
val groups: StateFlow<List<GroupWithRelationSimple>> = _groups.asStateFlow()

init {
launch {
_state.value = GetRelationState.Loading
getGroupListWithRelationUseCase()
getGroupListWithRelationSimpleUseCase()
.onSuccess {
_groups.value = it
}.onFailure { exception ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.history

sealed interface HistoryIntent
import ac.dnd.bookkeeping.android.presentation.model.history.HistoryViewType

sealed interface HistoryIntent {
data class ClickTab(val type: HistoryViewType) : HistoryIntent
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.home.history

import ac.dnd.bookkeeping.android.domain.model.feature.group.GroupWithRelationDetail
import ac.dnd.bookkeeping.android.domain.model.legacy.HistoryInfoLegacy
import ac.dnd.bookkeeping.android.presentation.model.history.HistoryViewType
import androidx.compose.runtime.Immutable

@Immutable
data class HistoryModel(
val state: HistoryState,
val historyInfo: HistoryInfoLegacy
val info: HistoryInfoLegacy,
val viewType: HistoryViewType,
val groups: List<GroupWithRelationDetail>
)
Loading

0 comments on commit b8d1023

Please sign in to comment.