EventStream.publish() can now receive vararg
This commit is contained in:
@@ -7,13 +7,17 @@ class EventStream<ID : AggregateId> {
|
||||
private val eventBus: MutableMap<ID, MutableList<Event<ID>>> = mutableMapOf()
|
||||
|
||||
fun publish(event: Event<ID>) {
|
||||
eventBus.getOrPut(event.aggregateId) { mutableListOf() }.add(event)
|
||||
eventBus.getOrPut(event.id) { mutableListOf() }.add(event)
|
||||
logger.atInfo {
|
||||
message = "Event published"
|
||||
message = "Event published: $event"
|
||||
payload = mapOf("event" to event)
|
||||
}
|
||||
}
|
||||
|
||||
fun publish(vararg events: Event<ID>) {
|
||||
events.forEach { publish(it) }
|
||||
}
|
||||
|
||||
fun <U : Event<ID>> read(
|
||||
aggregateId: ID,
|
||||
eventClass: Class<U>,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package eventDemo.app
|
||||
|
||||
sealed interface Event<ID : AggregateId> {
|
||||
val aggregateId: ID
|
||||
val id: ID
|
||||
}
|
||||
|
||||
data class PlayCardEvent(
|
||||
override val aggregateId: GameId,
|
||||
override val id: GameId,
|
||||
val card: Card,
|
||||
) : Event<GameId>
|
||||
|
||||
@@ -37,7 +37,7 @@ class Game(
|
||||
}
|
||||
}
|
||||
|
||||
fun Routing.putCard() {
|
||||
fun Routing.card() {
|
||||
val eventStream by inject<EventStream<GameId>>()
|
||||
|
||||
post<Game.Card.PutCard> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package eventDemo.plugins
|
||||
|
||||
import eventDemo.app.actions.putCard
|
||||
import eventDemo.app.actions.card
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.application.install
|
||||
@@ -24,8 +24,6 @@ fun Application.configureRouting() {
|
||||
}
|
||||
|
||||
routing {
|
||||
putCard()
|
||||
card()
|
||||
}
|
||||
}
|
||||
|
||||
private typealias ConverterDeclaration = Configuration.() -> Unit
|
||||
|
||||
Reference in New Issue
Block a user