expense-manager's People
expense-manager's Issues
flow { collect{} emit{} } data not retning in usecase
i want got get in different formate for that i write a logic but collect{}
method store data in entryGroup but after collect{}
method entryGroup
show empty and not return data.
Usecase
class GetEntriesByGroup(
private val repository: EntryRepository
) {
operator fun invoke(): Flow<List<EntryGroup>> {
return flow {
try {
val entries = repository.getEntries()
val entryGroups = mutableListOf<EntryGroup>()
entries.collect { entryList ->
val groupedEntries = entryList.groupBy { it.timestamp }
var index = 0
groupedEntries.map { (datetime, entries) ->
index++
var total = 0.0
entries.map {
total = if (it.paymentType) total + it.amount else total - it.amount
}
val adjustedEntries = entries.map { entry ->
Entry(
id = entry.id,
bookId = entry.bookId,
title = entry.title,
description = entry.description,
amount = entry.amount,
paymentType = entry.paymentType,
paymentMethod = entry.paymentMethod,
timestamp = entry.timestamp
)
}
entryGroups.add(
EntryGroup(
id = index,
datetime = datetime,
total = total,
data = adjustedEntries
)
)
Log.i("uttam2", entryGroups.toString())
}
Log.i("uttam3", entryGroups.toString())
}
val sortedEntryGroups = entryGroups.sortedByDescending { it.datetime }
emit(sortedEntryGroups)
} catch (e: Exception) {
// Handle and log the error
Log.e("GetEntriesByGroup", "Error in data retrieval: ${e.message}")
}
}
}
}
Data class
data class EntryGroup(
val id: Int,
val data: List<Entry>,
val datetime: Long,
val total: Double
)
data class Entry(
@PrimaryKey val id: Int? = null,
val bookId: Int,
val title: String,
val description: String,
val amount: Double,
val paymentType: Boolean,
val paymentMethod: Int,
val timestamp: Long
)
input data:
listOf{
BookEntryStruct(1, "Enrty 1", 400, "Aug 14, 2023"),
BookEntryStruct(1, "Enrty 2", -100.0, "Aug 14, 2023"),
BookEntryStruct(1, "Enrty 3", -50.0, "Aug 15, 2023"),
BookEntryStruct(1, "Enrty 4", -100.0, "Aug 15, 2023"),
}
i want output like this:
BookTabStruct(
1,
"Aug 15, 2023",
150.0,
listOf(
BookEntryStruct(4, "Enrty 4", -100.0, 150.0 ),
BookEntryStruct(3, "Enrty 3", -50.0, 250.0 ),
)
),
BookTabStruct(
2,
"Aug 14, 2023",
300.0,
listOf(
BookEntryStruct(2, "Enrty 2", -100.0, 300.0 ),
BookEntryStruct(1, "Enrty 1", 400.0, 400.0 ),
)
)
return data in group by date
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.