-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from YAPP-Github/feature/MZ-179-ledger-search
Feature/mz 179 ledger search
- Loading branch information
Showing
17 changed files
with
344 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.susu.core.model | ||
|
||
data class Category( | ||
val id: Int, | ||
val seq: Int, | ||
val category: String, | ||
val customCategory: String? = null, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.susu.core.model | ||
|
||
import androidx.compose.runtime.Stable | ||
import java.time.LocalDateTime | ||
|
||
@Stable | ||
data class Ledger( | ||
val id: Int, | ||
val title: String, | ||
val description: String, | ||
val startAt: LocalDateTime, | ||
val endAt: LocalDateTime, | ||
val category: Category, | ||
val totalAmounts: Int, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
data/src/main/java/com/susu/data/data/repository/LedgerRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.susu.data.data.repository | ||
|
||
import com.susu.core.model.Ledger | ||
import com.susu.data.remote.api.LedgerService | ||
import com.susu.data.remote.model.response.toModel | ||
import com.susu.domain.repository.LedgerRepository | ||
import kotlinx.datetime.toKotlinLocalDateTime | ||
import java.time.LocalDateTime | ||
import javax.inject.Inject | ||
|
||
class LedgerRepositoryImpl @Inject constructor( | ||
private val ledgerService: LedgerService, | ||
) : LedgerRepository { | ||
override suspend fun getLedgerList( | ||
title: String?, | ||
categoryId: Long?, | ||
fromStartAt: LocalDateTime, | ||
toEndAt: LocalDateTime, | ||
page: Int?, | ||
sort: String?, | ||
): List<Ledger> { | ||
return ledgerService.getLedgerList( | ||
title = title, | ||
categoryId = categoryId, | ||
fromStartAt = fromStartAt.toKotlinLocalDateTime(), | ||
toEndAt = toEndAt.toKotlinLocalDateTime(), | ||
page = page, | ||
sort = sort, | ||
).getOrThrow().toModel() | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
data/src/main/java/com/susu/data/remote/api/LedgerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.susu.data.remote.api | ||
|
||
import com.susu.data.remote.model.response.LedgerListResponse | ||
import com.susu.data.remote.retrofit.ApiResult | ||
import kotlinx.datetime.LocalDateTime | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface LedgerService { | ||
@GET("ledgers") | ||
suspend fun getLedgerList( | ||
@Query("title") title: String?, | ||
@Query("categoryId") categoryId: Long?, | ||
@Query("fromStartAt") fromStartAt: LocalDateTime, | ||
@Query("toEndAt") toEndAt: LocalDateTime, | ||
@Query("page") page: Int?, | ||
@Query("sort") sort: String?, | ||
): ApiResult<LedgerListResponse> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
data/src/main/java/com/susu/data/remote/model/response/LedgerListResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.susu.data.remote.model.response | ||
|
||
import com.susu.core.model.Category | ||
import kotlinx.datetime.LocalDateTime | ||
import kotlinx.datetime.toJavaLocalDateTime | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LedgerListResponse( | ||
@SerialName("data") | ||
val ledgerList: List<Ledger>, | ||
val page: Int, | ||
val size: Int, | ||
val totalPage: Int, | ||
val totalCount: Int, | ||
val sort: SortInfo, | ||
) | ||
|
||
@Serializable | ||
data class Ledger( | ||
@SerialName("ledger") | ||
val info: LedgerInfo, | ||
val category: CategoryInfo, | ||
val totalAmounts: Int, | ||
val totalCounts: Int, | ||
) | ||
|
||
@Serializable | ||
data class LedgerInfo( | ||
val id: Int, | ||
val title: String, | ||
val description: String, | ||
val startAt: LocalDateTime, | ||
val endAt: LocalDateTime, | ||
) | ||
|
||
@Serializable | ||
data class CategoryInfo( | ||
val id: Int, | ||
val seq: Int, | ||
val category: String, | ||
val customCategory: String? = null, | ||
) | ||
|
||
@Serializable | ||
data class SortInfo( | ||
val empty: Boolean, | ||
val unsorted: Boolean, | ||
val sorted: Boolean, | ||
) | ||
|
||
internal fun LedgerListResponse.toModel() = this.ledgerList.map { ledger -> | ||
with(ledger) { | ||
com.susu.core.model.Ledger( | ||
id = info.id, | ||
title = info.title, | ||
description = info.description, | ||
startAt = info.startAt.toJavaLocalDateTime(), | ||
endAt = info.endAt.toJavaLocalDateTime(), | ||
category = category.toModel(), | ||
totalAmounts = totalAmounts, | ||
) | ||
} | ||
} | ||
|
||
internal fun CategoryInfo.toModel() = Category( | ||
id = id, | ||
seq = seq, | ||
category = category, | ||
customCategory = customCategory, | ||
) |
15 changes: 15 additions & 0 deletions
15
domain/src/main/java/com/susu/domain/repository/LedgerRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.susu.domain.repository | ||
|
||
import com.susu.core.model.Ledger | ||
import java.time.LocalDateTime | ||
|
||
interface LedgerRepository { | ||
suspend fun getLedgerList( | ||
title: String?, | ||
categoryId: Long?, | ||
fromStartAt: LocalDateTime, | ||
toEndAt: LocalDateTime, | ||
page: Int?, | ||
sort: String?, | ||
): List<Ledger> | ||
} |
32 changes: 32 additions & 0 deletions
32
domain/src/main/java/com/susu/domain/usecase/ledger/GetLedgerListUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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 | ||
|
||
class GetLedgerListUseCase @Inject constructor( | ||
private val ledgerRepository: LedgerRepository, | ||
) { | ||
suspend operator fun invoke(param: Param) = runCatchingIgnoreCancelled { | ||
with(param) { | ||
ledgerRepository.getLedgerList( | ||
title = title, | ||
categoryId = categoryId, | ||
fromStartAt = fromStartAt, | ||
toEndAt = toEndAt, | ||
page = page, | ||
sort = sort, | ||
) | ||
} | ||
} | ||
|
||
data class Param( | ||
val title: String? = null, | ||
val categoryId: Long? = null, | ||
val fromStartAt: LocalDateTime = LocalDateTime.now().minusYears(10), | ||
val toEndAt: LocalDateTime = LocalDateTime.now(), | ||
val page: Int? = null, | ||
val sort: String? = null, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
feature/received/src/main/java/com/susu/feature/received/search/LedgerSearchContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
package com.susu.feature.received.search | ||
|
||
import com.susu.core.model.Ledger | ||
import com.susu.core.ui.base.SideEffect | ||
import com.susu.core.ui.base.UiState | ||
import kotlinx.collections.immutable.PersistentList | ||
import kotlinx.collections.immutable.persistentListOf | ||
|
||
data class LedgerSearchState( | ||
val searchKeyword: String = "", | ||
val searchKeywordList: PersistentList<String> = persistentListOf(), | ||
val recentSearchKeywordList: PersistentList<String> = persistentListOf(), | ||
val ledgerList: PersistentList<Ledger> = persistentListOf(), | ||
val isLoading: Boolean = false, | ||
val showSearchResultEmpty: Boolean = false, | ||
) : UiState | ||
|
||
sealed interface LedgerSearchSideEffect : SideEffect { | ||
data object PopBackStack : LedgerSearchSideEffect | ||
data class NavigateLedgerDetail(val id: Int) : LedgerSearchSideEffect | ||
} |
Oops, something went wrong.