fix: add date to filter

This commit is contained in:
Rafal Wisniewski
2026-05-06 12:47:11 +02:00
parent f83bf62655
commit 270ff4fa07
9 changed files with 204 additions and 132 deletions

View File

@@ -40,6 +40,12 @@ interface ExpenseDao {
AND (
:endAmount IS NULL OR expense.amount <= :endAmount
)
AND (
:startDate IS NULL OR expense.datetime >= :startDate
)
AND (
:endDate IS NULL OR expense.datetime <= :endDate
)
ORDER BY expense.datetime DESC
"""
@@ -50,7 +56,9 @@ interface ExpenseDao {
categoryIds: List<Int>,
categoriesEmpty: Boolean,
startAmount: Double?,
endAmount: Double?
endAmount: Double?,
startDate: Long?,
endDate: Long?
): PagingSource<Int, ExpenseDto>
@Transaction
@@ -74,7 +82,12 @@ interface ExpenseDao {
AND (
:endAmount IS NULL OR expense.amount <= :endAmount
)
AND (
:startDate IS NULL OR expense.datetime >= :startDate
)
AND (
:endDate IS NULL OR expense.datetime <= :endDate
)
ORDER BY expense.datetime DESC
"""
)
@@ -84,7 +97,9 @@ interface ExpenseDao {
categoryIds: List<Int>,
categoriesEmpty: Boolean,
startAmount: Double?,
endAmount: Double?
endAmount: Double?,
startDate: Long?,
endDate: Long?
): Flow<List<ExpenseDto>>
@Query(

View File

@@ -1,7 +1,5 @@
package cc.n0th1ng.tripmoney.data.repository
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.annotation.WorkerThread
import androidx.paging.Pager
import androidx.paging.PagingConfig
@@ -10,9 +8,11 @@ import cc.n0th1ng.tripmoney.Filter
import cc.n0th1ng.tripmoney.data.dao.ExpenseDao
import cc.n0th1ng.tripmoney.data.entity.Expense
import cc.n0th1ng.tripmoney.data.entity.ExpenseDto
import cc.n0th1ng.tripmoney.screens.listexpense.toEpochMilli
import cc.n0th1ng.tripmoney.utils.Currencies
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import java.time.LocalDate
import javax.inject.Inject
class ExpenseRepository @Inject constructor(
@@ -49,9 +49,10 @@ class ExpenseRepository @Inject constructor(
categoryIds = categoryIds,
categoriesEmpty = categoryIds.isEmpty(),
startAmount = filter.startAmount,
endAmount = filter.endAmount
endAmount = filter.endAmount,
startDate = if(filter.startDate == LocalDate.MIN) null else filter.startDate.toEpochMilli(),
endDate = if(filter.endDate == LocalDate.MAX) null else filter.endDate.plusDays(1).toEpochMilli(),
)
}
).flow
}
@@ -62,18 +63,18 @@ class ExpenseRepository @Inject constructor(
filter: Filter = Filter()
): Flow<List<ExpenseDto>> {
val categoryIds = filter.categories.map { it.id }
return expenseDao.expenseDto(
tripId = tripId,
search = search.takeIf { it.isNotBlank() },
categoryIds = categoryIds,
categoriesEmpty = categoryIds.isEmpty(),
startAmount = filter.startAmount,
endAmount = filter.endAmount
endAmount = filter.endAmount,
startDate = if(filter.startDate == LocalDate.MIN) null else filter.startDate.toEpochMilli(),
endDate = if(filter.endDate == LocalDate.MAX) null else filter.endDate.plusDays(1).toEpochMilli(),
)
}
@RequiresApi(Build.VERSION_CODES.O)
suspend fun recalculateTripExpenses(tripId: Int) {
val expenses = getExpensesDto(tripId).first()
expenses.forEach { expenseDto ->