Implement first routes & tests

install Koin
install kotest
declare first events
create EventStream
This commit is contained in:
2024-02-28 23:31:55 +01:00
parent 5434c59129
commit 43b5f27e50
21 changed files with 422 additions and 72 deletions

View File

@@ -0,0 +1,27 @@
package eventDemo.app
import io.github.oshai.kotlinlogging.KotlinLogging
class EventStream<ID : AggregateId> {
private val logger = KotlinLogging.logger {}
private val eventBus: MutableMap<ID, MutableList<Event<ID>>> = mutableMapOf()
fun publish(event: Event<ID>) {
eventBus.getOrPut(event.aggregateId) { mutableListOf() }.add(event)
logger.atInfo {
message = "Event published"
payload = mapOf("event" to event)
}
}
fun <U : Event<ID>> read(
aggregateId: ID,
eventClass: Class<U>,
): U? {
return eventBus.get(aggregateId)?.filterIsInstance(eventClass)?.firstOrNull()
}
}
inline fun <reified U : Event<ID>, ID : AggregateId> EventStream<ID>.read(aggregateId: ID): U? {
return this.read(aggregateId, U::class.java)
}