From 769d1040403cddef331bd4dae0de7c4ff0fe6109 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Sun, 16 Mar 2025 02:47:08 +0100 Subject: [PATCH] Move file and add interface to improve Archi Hexa --- .../event/GameEventBusInMemory.kt | 11 ++++ .../event/GameEventStoreInMemory.kt | 14 +++++ .../event/projection/GameStateRepository.kt | 23 ++++---- .../GameCommandRouteWebSocket.kt | 12 +++-- .../interfaceLayer}/ReadTheGameState.kt | 6 +-- .../app/command/GameCommandActionRunner.kt | 27 ---------- .../eventDemo/app/event/GameEventBus.kt | 9 ---- .../eventDemo/app/event/GameEventStore.kt | 12 ----- .../app/event/event/PlayerActionEvent.kt | 7 --- .../command/CommandException.kt | 2 +- .../command/GameCommandActionRunner.kt | 27 ++++++++++ .../command/GameCommandHandler.kt | 22 ++++---- .../command/action/CommandAction.kt | 4 +- .../command/action/ICantPlay.kt | 12 ++--- .../command/action/IWantToJoinTheGame.kt | 12 ++--- .../command/action/IWantToPlayCard.kt | 12 ++--- .../command/action/IamReadyToPlay.kt | 12 ++--- .../command/command/GameCommand.kt | 6 +-- .../command/command/ICantPlayCommand.kt | 6 +-- .../command/IWantToJoinTheGameCommand.kt | 6 +-- .../command/command/IWantToPlayCardCommand.kt | 8 +-- .../command/command/IamReadyToPlayCommand.kt | 6 +-- .../{app => business}/entity/Card.kt | 2 +- .../{app => business}/entity/Deck.kt | 2 +- .../{app => business}/entity/GameId.kt | 2 +- .../{app => business}/entity/Player.kt | 2 +- .../{app => business}/entity/PlayersHands.kt | 2 +- .../{app => business}/event/EventHandler.kt | 4 +- .../eventDemo/business/event/GameEventBus.kt | 7 +++ .../event/GameEventHandler.kt | 10 ++-- .../business/event/GameEventStore.kt | 7 +++ .../event/event/CardIsPlayedEvent.kt | 8 +-- .../event/event/GameEvent.kt | 4 +- .../event/event/GameStartedEvent.kt | 10 ++-- .../event/event/NewPlayerEvent.kt | 6 +-- .../business/event/event/PlayerActionEvent.kt | 7 +++ .../event/event/PlayerChoseColorEvent.kt | 8 +-- .../event/event/PlayerHavePassEvent.kt | 8 +-- .../event/event/PlayerReadyEvent.kt | 6 +-- .../event/event/PlayerWinEvent.kt | 6 +-- .../PlayerNotificationEventListener.kt | 54 +++++++++---------- .../eventListener/ReactionEventListener.kt | 18 +++---- .../event/projection/GameState.kt | 10 ++-- .../event/projection/GameStateBuilder.kt | 22 ++++---- .../event/projection/GameStateRepository.kt | 10 ++++ .../event/projection/Projection.kt | 2 +- .../notification/CommandErrorNotification.kt | 2 +- .../notification/CommandNotification.kt | 2 +- .../CommandSuccessNotification.kt | 2 +- .../notification/ItsTheTurnOfNotification.kt | 4 +- .../notification/Notification.kt | 2 +- .../PlayerAsJoinTheGameNotification.kt | 4 +- .../PlayerAsPlayACardNotification.kt | 6 +-- .../PlayerHavePassNotification.kt | 4 +- .../PlayerWasChoseTheCardColorNotification.kt | 6 +-- .../PlayerWasReadyNotification.kt | 4 +- .../notification/PlayerWinNotification.kt | 4 +- .../TheGameWasStartedNotification.kt | 4 +- .../WelcomeToTheGameNotification.kt | 4 +- .../notification/YourNewCardNotification.kt | 4 +- .../eventDemo/configuration/ConfigureAuth.kt | 2 +- .../eventDemo/configuration/ConfigureDI.kt | 38 +++++++------ .../configuration/ConfigureDIAction.kt | 8 +-- .../configuration/ConfigureGameListener.kt | 2 +- .../configuration/ConfigureSerialization.kt | 4 +- .../configuration/DeclareHttpRoutes.kt | 2 +- .../DeclareWebSocketsGameRoute.kt | 6 +-- .../ProjectionSnapshotRepositoryInMemory.kt | 5 +- src/test/kotlin/eventDemo/Helpers.kt | 4 +- .../app/command/GameCommandHandlerTest.kt | 22 ++++---- .../kotlin/eventDemo/app/entity/DeckTest.kt | 3 ++ .../eventDemo/app/entity/PlayerHandKtTest.kt | 3 ++ .../event/projection/GameStateBuilderTest.kt | 18 ++++--- .../projection/GameStateRepositoryTest.kt | 9 ++-- ...rojectionSnapshotRepositoryInMemoryTest.kt | 3 ++ .../eventDemo/app/query/GameStateRouteTest.kt | 20 +++---- .../eventDemo/app/query/GameStateTest.kt | 51 +++++++++--------- 77 files changed, 388 insertions(+), 337 deletions(-) create mode 100644 src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventBusInMemory.kt create mode 100644 src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventStoreInMemory.kt rename src/main/kotlin/eventDemo/{app => adapter/infrastructureLayer}/event/projection/GameStateRepository.kt (58%) rename src/main/kotlin/eventDemo/{app/command => adapter/interfaceLayer}/GameCommandRouteWebSocket.kt (76%) rename src/main/kotlin/eventDemo/{app/query => adapter/interfaceLayer}/ReadTheGameState.kt (89%) delete mode 100644 src/main/kotlin/eventDemo/app/command/GameCommandActionRunner.kt delete mode 100644 src/main/kotlin/eventDemo/app/event/GameEventBus.kt delete mode 100644 src/main/kotlin/eventDemo/app/event/GameEventStore.kt delete mode 100644 src/main/kotlin/eventDemo/app/event/event/PlayerActionEvent.kt rename src/main/kotlin/eventDemo/{app => business}/command/CommandException.kt (69%) create mode 100644 src/main/kotlin/eventDemo/business/command/GameCommandActionRunner.kt rename src/main/kotlin/eventDemo/{app => business}/command/GameCommandHandler.kt (88%) rename src/main/kotlin/eventDemo/{app => business}/command/action/CommandAction.kt (61%) rename src/main/kotlin/eventDemo/{app => business}/command/action/ICantPlay.kt (71%) rename src/main/kotlin/eventDemo/{app => business}/command/action/IWantToJoinTheGame.kt (61%) rename src/main/kotlin/eventDemo/{app => business}/command/action/IWantToPlayCard.kt (70%) rename src/main/kotlin/eventDemo/{app => business}/command/action/IamReadyToPlay.kt (72%) rename src/main/kotlin/eventDemo/{app => business}/command/command/GameCommand.kt (68%) rename src/main/kotlin/eventDemo/{app => business}/command/command/ICantPlayCommand.kt (77%) rename src/main/kotlin/eventDemo/{app => business}/command/command/IWantToJoinTheGameCommand.kt (77%) rename src/main/kotlin/eventDemo/{app => business}/command/command/IWantToPlayCardCommand.kt (73%) rename src/main/kotlin/eventDemo/{app => business}/command/command/IamReadyToPlayCommand.kt (76%) rename src/main/kotlin/eventDemo/{app => business}/entity/Card.kt (98%) rename src/main/kotlin/eventDemo/{app => business}/entity/Deck.kt (99%) rename src/main/kotlin/eventDemo/{app => business}/entity/GameId.kt (91%) rename src/main/kotlin/eventDemo/{app => business}/entity/Player.kt (95%) rename src/main/kotlin/eventDemo/{app => business}/entity/PlayersHands.kt (97%) rename src/main/kotlin/eventDemo/{app => business}/event/EventHandler.kt (74%) create mode 100644 src/main/kotlin/eventDemo/business/event/GameEventBus.kt rename src/main/kotlin/eventDemo/{app => business}/event/GameEventHandler.kt (88%) create mode 100644 src/main/kotlin/eventDemo/business/event/GameEventStore.kt rename src/main/kotlin/eventDemo/{app => business}/event/event/CardIsPlayedEvent.kt (73%) rename src/main/kotlin/eventDemo/{app => business}/event/event/GameEvent.kt (78%) rename src/main/kotlin/eventDemo/{app => business}/event/event/GameStartedEvent.kt (83%) rename src/main/kotlin/eventDemo/{app => business}/event/event/NewPlayerEvent.kt (76%) create mode 100644 src/main/kotlin/eventDemo/business/event/event/PlayerActionEvent.kt rename src/main/kotlin/eventDemo/{app => business}/event/event/PlayerChoseColorEvent.kt (74%) rename src/main/kotlin/eventDemo/{app => business}/event/event/PlayerHavePassEvent.kt (73%) rename src/main/kotlin/eventDemo/{app => business}/event/event/PlayerReadyEvent.kt (76%) rename src/main/kotlin/eventDemo/{app => business}/event/event/PlayerWinEvent.kt (76%) rename src/main/kotlin/eventDemo/{app => business/event}/eventListener/PlayerNotificationEventListener.kt (69%) rename src/main/kotlin/eventDemo/{app => business/event}/eventListener/ReactionEventListener.kt (79%) rename src/main/kotlin/eventDemo/{app => business}/event/projection/GameState.kt (95%) rename src/main/kotlin/eventDemo/{app => business}/event/projection/GameStateBuilder.kt (83%) create mode 100644 src/main/kotlin/eventDemo/business/event/projection/GameStateRepository.kt rename src/main/kotlin/eventDemo/{app => business}/event/projection/Projection.kt (75%) rename src/main/kotlin/eventDemo/{app => business}/notification/CommandErrorNotification.kt (90%) rename src/main/kotlin/eventDemo/{app => business}/notification/CommandNotification.kt (56%) rename src/main/kotlin/eventDemo/{app => business}/notification/CommandSuccessNotification.kt (90%) rename src/main/kotlin/eventDemo/{app => business}/notification/ItsTheTurnOfNotification.kt (78%) rename src/main/kotlin/eventDemo/{app => business}/notification/Notification.kt (84%) rename src/main/kotlin/eventDemo/{app => business}/notification/PlayerAsJoinTheGameNotification.kt (78%) rename src/main/kotlin/eventDemo/{app => business}/notification/PlayerAsPlayACardNotification.kt (72%) rename src/main/kotlin/eventDemo/{app => business}/notification/PlayerHavePassNotification.kt (78%) rename src/main/kotlin/eventDemo/{app => business}/notification/PlayerWasChoseTheCardColorNotification.kt (73%) rename src/main/kotlin/eventDemo/{app => business}/notification/PlayerWasReadyNotification.kt (78%) rename src/main/kotlin/eventDemo/{app => business}/notification/PlayerWinNotification.kt (78%) rename src/main/kotlin/eventDemo/{app => business}/notification/TheGameWasStartedNotification.kt (79%) rename src/main/kotlin/eventDemo/{app => business}/notification/WelcomeToTheGameNotification.kt (79%) rename src/main/kotlin/eventDemo/{app => business}/notification/YourNewCardNotification.kt (78%) rename src/main/kotlin/eventDemo/{app => libs}/event/projection/ProjectionSnapshotRepositoryInMemory.kt (97%) diff --git a/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventBusInMemory.kt b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventBusInMemory.kt new file mode 100644 index 0000000..49ab033 --- /dev/null +++ b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventBusInMemory.kt @@ -0,0 +1,11 @@ +package eventDemo.adapter.infrastructureLayer.event + +import eventDemo.business.entity.GameId +import eventDemo.business.event.GameEventBus +import eventDemo.business.event.event.GameEvent +import eventDemo.libs.event.EventBus +import eventDemo.libs.event.EventBusInMemory + +class GameEventBusInMemory : + GameEventBus, + EventBus by EventBusInMemory() diff --git a/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventStoreInMemory.kt b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventStoreInMemory.kt new file mode 100644 index 0000000..c561089 --- /dev/null +++ b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/GameEventStoreInMemory.kt @@ -0,0 +1,14 @@ +package eventDemo.adapter.infrastructureLayer.event + +import eventDemo.business.entity.GameId +import eventDemo.business.event.GameEventStore +import eventDemo.business.event.event.GameEvent +import eventDemo.libs.event.EventStore +import eventDemo.libs.event.EventStoreInMemory + +/** + * A stream to publish and read the played card event. + */ +class GameEventStoreInMemory : + GameEventStore, + EventStore by EventStoreInMemory() diff --git a/src/main/kotlin/eventDemo/app/event/projection/GameStateRepository.kt b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameStateRepository.kt similarity index 58% rename from src/main/kotlin/eventDemo/app/event/projection/GameStateRepository.kt rename to src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameStateRepository.kt index a5f14d2..5d9b57b 100644 --- a/src/main/kotlin/eventDemo/app/event/projection/GameStateRepository.kt +++ b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameStateRepository.kt @@ -1,15 +1,20 @@ -package eventDemo.app.event.projection +package eventDemo.adapter.infrastructureLayer.event.projection -import eventDemo.app.entity.GameId -import eventDemo.app.event.GameEventHandler -import eventDemo.app.event.GameEventStore -import eventDemo.app.event.event.GameEvent +import eventDemo.business.entity.GameId +import eventDemo.business.event.GameEventHandler +import eventDemo.business.event.GameEventStore +import eventDemo.business.event.event.GameEvent +import eventDemo.business.event.projection.GameState +import eventDemo.business.event.projection.GameStateRepository +import eventDemo.business.event.projection.apply +import eventDemo.libs.event.projection.ProjectionSnapshotRepositoryInMemory +import eventDemo.libs.event.projection.SnapshotConfig -class GameStateRepository( +class GameStateRepositoryInMemory( eventStore: GameEventStore, eventHandler: GameEventHandler, snapshotConfig: SnapshotConfig = SnapshotConfig(), -) { +) : GameStateRepository { private val projectionsSnapshot = ProjectionSnapshotRepositoryInMemory( eventStore = eventStore, @@ -29,7 +34,7 @@ class GameStateRepository( * * It fetches it from the local cache if possible, otherwise it builds it. */ - fun getLast(gameId: GameId): GameState = + override fun getLast(gameId: GameId): GameState = projectionsSnapshot.getLast(gameId) /** @@ -38,6 +43,6 @@ class GameStateRepository( * * It fetches it from the local cache if possible, otherwise it builds it. */ - fun getUntil(event: GameEvent): GameState = + override fun getUntil(event: GameEvent): GameState = projectionsSnapshot.getUntil(event) } diff --git a/src/main/kotlin/eventDemo/app/command/GameCommandRouteWebSocket.kt b/src/main/kotlin/eventDemo/adapter/interfaceLayer/GameCommandRouteWebSocket.kt similarity index 76% rename from src/main/kotlin/eventDemo/app/command/GameCommandRouteWebSocket.kt rename to src/main/kotlin/eventDemo/adapter/interfaceLayer/GameCommandRouteWebSocket.kt index 6add4db..be3899c 100644 --- a/src/main/kotlin/eventDemo/app/command/GameCommandRouteWebSocket.kt +++ b/src/main/kotlin/eventDemo/adapter/interfaceLayer/GameCommandRouteWebSocket.kt @@ -1,8 +1,9 @@ -package eventDemo.app.command +package eventDemo.adapter.interfaceLayer -import eventDemo.app.entity.Player -import eventDemo.app.eventListener.PlayerNotificationEventListener -import eventDemo.app.notification.Notification +import eventDemo.business.command.GameCommandHandler +import eventDemo.business.entity.Player +import eventDemo.business.event.eventListener.PlayerNotificationEventListener +import eventDemo.business.notification.Notification import eventDemo.libs.fromFrameChannel import eventDemo.libs.toObjectChannel import io.github.oshai.kotlinlogging.withLoggingContext @@ -15,6 +16,7 @@ import io.ktor.server.websocket.webSocket import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.SendChannel +import kotlinx.coroutines.channels.trySendBlocking import kotlinx.coroutines.launch @DelicateCoroutinesApi @@ -34,7 +36,7 @@ fun Route.gameWebSocket( outgoingFrameChannel, ) } - playerNotificationListener.startListening(outgoingFrameChannel, currentPlayer) + playerNotificationListener.startListening({ outgoingFrameChannel.trySendBlocking(it) }, currentPlayer) } } } diff --git a/src/main/kotlin/eventDemo/app/query/ReadTheGameState.kt b/src/main/kotlin/eventDemo/adapter/interfaceLayer/ReadTheGameState.kt similarity index 89% rename from src/main/kotlin/eventDemo/app/query/ReadTheGameState.kt rename to src/main/kotlin/eventDemo/adapter/interfaceLayer/ReadTheGameState.kt index 0c16e72..eca7a91 100644 --- a/src/main/kotlin/eventDemo/app/query/ReadTheGameState.kt +++ b/src/main/kotlin/eventDemo/adapter/interfaceLayer/ReadTheGameState.kt @@ -1,7 +1,7 @@ -package eventDemo.app.query +package eventDemo.adapter.interfaceLayer -import eventDemo.app.entity.GameId -import eventDemo.app.event.projection.GameStateRepository +import eventDemo.business.entity.GameId +import eventDemo.business.event.projection.GameStateRepository import eventDemo.configuration.GameIdSerializer import io.ktor.http.HttpStatusCode import io.ktor.resources.Resource diff --git a/src/main/kotlin/eventDemo/app/command/GameCommandActionRunner.kt b/src/main/kotlin/eventDemo/app/command/GameCommandActionRunner.kt deleted file mode 100644 index a82e08b..0000000 --- a/src/main/kotlin/eventDemo/app/command/GameCommandActionRunner.kt +++ /dev/null @@ -1,27 +0,0 @@ -package eventDemo.app.command - -import eventDemo.app.command.action.ICantPlay -import eventDemo.app.command.action.IWantToJoinTheGame -import eventDemo.app.command.action.IWantToPlayCard -import eventDemo.app.command.action.IamReadyToPlay -import eventDemo.app.command.command.GameCommand -import eventDemo.app.command.command.ICantPlayCommand -import eventDemo.app.command.command.IWantToJoinTheGameCommand -import eventDemo.app.command.command.IWantToPlayCardCommand -import eventDemo.app.command.command.IamReadyToPlayCommand -import eventDemo.app.event.event.GameEvent - -class GameCommandActionRunner( - private val iWantToPlayCard: IWantToPlayCard, - private val iamReadyToPlay: IamReadyToPlay, - private val iWantToJoinTheGame: IWantToJoinTheGame, - private val iCantPlay: ICantPlay, -) { - fun run(command: GameCommand): (Int) -> GameEvent = - when (command) { - is IWantToPlayCardCommand -> iWantToPlayCard.run(command) - is IamReadyToPlayCommand -> iamReadyToPlay.run(command) - is IWantToJoinTheGameCommand -> iWantToJoinTheGame.run(command) - is ICantPlayCommand -> iCantPlay.run(command) - } -} diff --git a/src/main/kotlin/eventDemo/app/event/GameEventBus.kt b/src/main/kotlin/eventDemo/app/event/GameEventBus.kt deleted file mode 100644 index ea4e79d..0000000 --- a/src/main/kotlin/eventDemo/app/event/GameEventBus.kt +++ /dev/null @@ -1,9 +0,0 @@ -package eventDemo.app.event - -import eventDemo.app.entity.GameId -import eventDemo.app.event.event.GameEvent -import eventDemo.libs.event.EventBus - -class GameEventBus( - bus: EventBus, -) : EventBus by bus diff --git a/src/main/kotlin/eventDemo/app/event/GameEventStore.kt b/src/main/kotlin/eventDemo/app/event/GameEventStore.kt deleted file mode 100644 index 61e8bb3..0000000 --- a/src/main/kotlin/eventDemo/app/event/GameEventStore.kt +++ /dev/null @@ -1,12 +0,0 @@ -package eventDemo.app.event - -import eventDemo.app.entity.GameId -import eventDemo.app.event.event.GameEvent -import eventDemo.libs.event.EventStore - -/** - * A stream to publish and read the played card event. - */ -class GameEventStore( - private val eventStore: EventStore, -) : EventStore by eventStore diff --git a/src/main/kotlin/eventDemo/app/event/event/PlayerActionEvent.kt b/src/main/kotlin/eventDemo/app/event/event/PlayerActionEvent.kt deleted file mode 100644 index f1f4fd5..0000000 --- a/src/main/kotlin/eventDemo/app/event/event/PlayerActionEvent.kt +++ /dev/null @@ -1,7 +0,0 @@ -package eventDemo.app.event.event - -import eventDemo.app.entity.Player - -sealed interface PlayerActionEvent : GameEvent { - val player: Player -} diff --git a/src/main/kotlin/eventDemo/app/command/CommandException.kt b/src/main/kotlin/eventDemo/business/command/CommandException.kt similarity index 69% rename from src/main/kotlin/eventDemo/app/command/CommandException.kt rename to src/main/kotlin/eventDemo/business/command/CommandException.kt index 2c518c5..6b487c0 100644 --- a/src/main/kotlin/eventDemo/app/command/CommandException.kt +++ b/src/main/kotlin/eventDemo/business/command/CommandException.kt @@ -1,4 +1,4 @@ -package eventDemo.app.command +package eventDemo.business.command class CommandException( override val message: String, diff --git a/src/main/kotlin/eventDemo/business/command/GameCommandActionRunner.kt b/src/main/kotlin/eventDemo/business/command/GameCommandActionRunner.kt new file mode 100644 index 0000000..7b4701e --- /dev/null +++ b/src/main/kotlin/eventDemo/business/command/GameCommandActionRunner.kt @@ -0,0 +1,27 @@ +package eventDemo.business.command + +import eventDemo.business.command.action.ICantPlay +import eventDemo.business.command.action.IWantToJoinTheGame +import eventDemo.business.command.action.IWantToPlayCard +import eventDemo.business.command.action.IamReadyToPlay +import eventDemo.business.command.command.GameCommand +import eventDemo.business.command.command.ICantPlayCommand +import eventDemo.business.command.command.IWantToJoinTheGameCommand +import eventDemo.business.command.command.IWantToPlayCardCommand +import eventDemo.business.command.command.IamReadyToPlayCommand +import eventDemo.business.event.event.GameEvent + +class GameCommandActionRunner( + private val iWantToPlayCard: IWantToPlayCard, + private val iamReadyToPlay: IamReadyToPlay, + private val iWantToJoinTheGame: IWantToJoinTheGame, + private val iCantPlay: ICantPlay, +) { + fun run(command: GameCommand): (version: Int) -> GameEvent = + when (command) { + is IWantToPlayCardCommand -> iWantToPlayCard.run(command) + is IamReadyToPlayCommand -> iamReadyToPlay.run(command) + is IWantToJoinTheGameCommand -> iWantToJoinTheGame.run(command) + is ICantPlayCommand -> iCantPlay.run(command) + } +} diff --git a/src/main/kotlin/eventDemo/app/command/GameCommandHandler.kt b/src/main/kotlin/eventDemo/business/command/GameCommandHandler.kt similarity index 88% rename from src/main/kotlin/eventDemo/app/command/GameCommandHandler.kt rename to src/main/kotlin/eventDemo/business/command/GameCommandHandler.kt index 00e42f8..4ae4b15 100644 --- a/src/main/kotlin/eventDemo/app/command/GameCommandHandler.kt +++ b/src/main/kotlin/eventDemo/business/command/GameCommandHandler.kt @@ -1,13 +1,13 @@ -package eventDemo.app.command +package eventDemo.business.command -import eventDemo.app.command.command.GameCommand -import eventDemo.app.entity.Player -import eventDemo.app.event.GameEventBus -import eventDemo.app.event.GameEventHandler -import eventDemo.app.event.event.GameEvent -import eventDemo.app.notification.CommandErrorNotification -import eventDemo.app.notification.CommandSuccessNotification -import eventDemo.app.notification.Notification +import eventDemo.business.command.command.GameCommand +import eventDemo.business.entity.Player +import eventDemo.business.event.GameEventBus +import eventDemo.business.event.GameEventHandler +import eventDemo.business.event.event.GameEvent +import eventDemo.business.notification.CommandErrorNotification +import eventDemo.business.notification.CommandSuccessNotification +import eventDemo.business.notification.Notification import eventDemo.libs.command.CommandId import eventDemo.libs.command.CommandStreamChannel import io.github.oshai.kotlinlogging.KotlinLogging @@ -62,7 +62,7 @@ class GameCommandHandler( withLoggingContext("command" to command.toString()) { if (command.payload.player.id != player.id) { logger.warn { "Handle command Refuse, the player of the command is not the same" } - channelNotification.sendError(command)("You are not the author of this command\n") + channelNotification.sendError(command)("You are not the author of this command") } else { logger.info { "Handle command" } try { @@ -94,7 +94,7 @@ private fun SendChannel.sendSuccess(commandId: CommandId): suspend } } -private fun SendChannel.sendError(command: GameCommand): suspend (String) -> Unit = +private fun SendChannel.sendError(command: GameCommand): suspend (message: String) -> Unit = { val logger = KotlinLogging.logger { } CommandErrorNotification(message = it, command = command) diff --git a/src/main/kotlin/eventDemo/app/command/action/CommandAction.kt b/src/main/kotlin/eventDemo/business/command/action/CommandAction.kt similarity index 61% rename from src/main/kotlin/eventDemo/app/command/action/CommandAction.kt rename to src/main/kotlin/eventDemo/business/command/action/CommandAction.kt index 847a40a..86e295f 100644 --- a/src/main/kotlin/eventDemo/app/command/action/CommandAction.kt +++ b/src/main/kotlin/eventDemo/business/command/action/CommandAction.kt @@ -1,8 +1,8 @@ -package eventDemo.app.command.action +package eventDemo.business.command.action import eventDemo.libs.command.Command import eventDemo.libs.event.Event sealed interface CommandAction> { - fun run(command: C): (Int) -> E + fun run(command: C): (version: Int) -> E } diff --git a/src/main/kotlin/eventDemo/app/command/action/ICantPlay.kt b/src/main/kotlin/eventDemo/business/command/action/ICantPlay.kt similarity index 71% rename from src/main/kotlin/eventDemo/app/command/action/ICantPlay.kt rename to src/main/kotlin/eventDemo/business/command/action/ICantPlay.kt index e83f989..0d365e8 100644 --- a/src/main/kotlin/eventDemo/app/command/action/ICantPlay.kt +++ b/src/main/kotlin/eventDemo/business/command/action/ICantPlay.kt @@ -1,9 +1,9 @@ -package eventDemo.app.command.action +package eventDemo.business.command.action -import eventDemo.app.command.CommandException -import eventDemo.app.command.command.ICantPlayCommand -import eventDemo.app.event.event.PlayerHavePassEvent -import eventDemo.app.event.projection.GameStateRepository +import eventDemo.business.command.CommandException +import eventDemo.business.command.command.ICantPlayCommand +import eventDemo.business.event.event.PlayerHavePassEvent +import eventDemo.business.event.projection.GameStateRepository /** * A command to perform an action to play a new card @@ -11,7 +11,7 @@ import eventDemo.app.event.projection.GameStateRepository data class ICantPlay( private val gameStateRepository: GameStateRepository, ) : CommandAction { - override fun run(command: ICantPlayCommand): (Int) -> PlayerHavePassEvent { + override fun run(command: ICantPlayCommand): (version: Int) -> PlayerHavePassEvent { val state = gameStateRepository.getLast(command.payload.aggregateId) if (state.currentPlayerTurn != command.payload.player) { diff --git a/src/main/kotlin/eventDemo/app/command/action/IWantToJoinTheGame.kt b/src/main/kotlin/eventDemo/business/command/action/IWantToJoinTheGame.kt similarity index 61% rename from src/main/kotlin/eventDemo/app/command/action/IWantToJoinTheGame.kt rename to src/main/kotlin/eventDemo/business/command/action/IWantToJoinTheGame.kt index 69fb04e..29f5ca4 100644 --- a/src/main/kotlin/eventDemo/app/command/action/IWantToJoinTheGame.kt +++ b/src/main/kotlin/eventDemo/business/command/action/IWantToJoinTheGame.kt @@ -1,9 +1,9 @@ -package eventDemo.app.command.action +package eventDemo.business.command.action -import eventDemo.app.command.CommandException -import eventDemo.app.command.command.IWantToJoinTheGameCommand -import eventDemo.app.event.event.NewPlayerEvent -import eventDemo.app.event.projection.GameStateRepository +import eventDemo.business.command.CommandException +import eventDemo.business.command.command.IWantToJoinTheGameCommand +import eventDemo.business.event.event.NewPlayerEvent +import eventDemo.business.event.projection.GameStateRepository /** * A command to perform an action to play a new card @@ -11,7 +11,7 @@ import eventDemo.app.event.projection.GameStateRepository data class IWantToJoinTheGame( private val gameStateRepository: GameStateRepository, ) : CommandAction { - override fun run(command: IWantToJoinTheGameCommand): (Int) -> NewPlayerEvent { + override fun run(command: IWantToJoinTheGameCommand): (version: Int) -> NewPlayerEvent { val state = gameStateRepository.getLast(command.payload.aggregateId) if (!state.isStarted) { return { diff --git a/src/main/kotlin/eventDemo/app/command/action/IWantToPlayCard.kt b/src/main/kotlin/eventDemo/business/command/action/IWantToPlayCard.kt similarity index 70% rename from src/main/kotlin/eventDemo/app/command/action/IWantToPlayCard.kt rename to src/main/kotlin/eventDemo/business/command/action/IWantToPlayCard.kt index e93efe2..6266aa7 100644 --- a/src/main/kotlin/eventDemo/app/command/action/IWantToPlayCard.kt +++ b/src/main/kotlin/eventDemo/business/command/action/IWantToPlayCard.kt @@ -1,9 +1,9 @@ -package eventDemo.app.command.action +package eventDemo.business.command.action -import eventDemo.app.command.CommandException -import eventDemo.app.command.command.IWantToPlayCardCommand -import eventDemo.app.event.event.CardIsPlayedEvent -import eventDemo.app.event.projection.GameStateRepository +import eventDemo.business.command.CommandException +import eventDemo.business.command.command.IWantToPlayCardCommand +import eventDemo.business.event.event.CardIsPlayedEvent +import eventDemo.business.event.projection.GameStateRepository /** * A command to perform an action to play a new card @@ -11,7 +11,7 @@ import eventDemo.app.event.projection.GameStateRepository data class IWantToPlayCard( private val gameStateRepository: GameStateRepository, ) : CommandAction { - override fun run(command: IWantToPlayCardCommand): (Int) -> CardIsPlayedEvent { + override fun run(command: IWantToPlayCardCommand): (version: Int) -> CardIsPlayedEvent { val state = gameStateRepository.getLast(command.payload.aggregateId) if (!state.isStarted) { diff --git a/src/main/kotlin/eventDemo/app/command/action/IamReadyToPlay.kt b/src/main/kotlin/eventDemo/business/command/action/IamReadyToPlay.kt similarity index 72% rename from src/main/kotlin/eventDemo/app/command/action/IamReadyToPlay.kt rename to src/main/kotlin/eventDemo/business/command/action/IamReadyToPlay.kt index 6998503..0213419 100644 --- a/src/main/kotlin/eventDemo/app/command/action/IamReadyToPlay.kt +++ b/src/main/kotlin/eventDemo/business/command/action/IamReadyToPlay.kt @@ -1,9 +1,9 @@ -package eventDemo.app.command.action +package eventDemo.business.command.action -import eventDemo.app.command.CommandException -import eventDemo.app.command.command.IamReadyToPlayCommand -import eventDemo.app.event.event.PlayerReadyEvent -import eventDemo.app.event.projection.GameStateRepository +import eventDemo.business.command.CommandException +import eventDemo.business.command.command.IamReadyToPlayCommand +import eventDemo.business.event.event.PlayerReadyEvent +import eventDemo.business.event.projection.GameStateRepository /** * A command to set as ready to play @@ -12,7 +12,7 @@ class IamReadyToPlay( private val gameStateRepository: GameStateRepository, ) : CommandAction { @Throws(CommandException::class) - override fun run(command: IamReadyToPlayCommand): (Int) -> PlayerReadyEvent { + override fun run(command: IamReadyToPlayCommand): (version: Int) -> PlayerReadyEvent { val state = gameStateRepository.getLast(command.payload.aggregateId) val playerExist: Boolean = state.players.contains(command.payload.player) val playerIsAlreadyReady: Boolean = state.readyPlayers.contains(command.payload.player) diff --git a/src/main/kotlin/eventDemo/app/command/command/GameCommand.kt b/src/main/kotlin/eventDemo/business/command/command/GameCommand.kt similarity index 68% rename from src/main/kotlin/eventDemo/app/command/command/GameCommand.kt rename to src/main/kotlin/eventDemo/business/command/command/GameCommand.kt index 1687895..4387f83 100644 --- a/src/main/kotlin/eventDemo/app/command/command/GameCommand.kt +++ b/src/main/kotlin/eventDemo/business/command/command/GameCommand.kt @@ -1,7 +1,7 @@ -package eventDemo.app.command.command +package eventDemo.business.command.command -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import eventDemo.libs.command.Command import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/eventDemo/app/command/command/ICantPlayCommand.kt b/src/main/kotlin/eventDemo/business/command/command/ICantPlayCommand.kt similarity index 77% rename from src/main/kotlin/eventDemo/app/command/command/ICantPlayCommand.kt rename to src/main/kotlin/eventDemo/business/command/command/ICantPlayCommand.kt index 58bb28a..d01588e 100644 --- a/src/main/kotlin/eventDemo/app/command/command/ICantPlayCommand.kt +++ b/src/main/kotlin/eventDemo/business/command/command/ICantPlayCommand.kt @@ -1,7 +1,7 @@ -package eventDemo.app.command.command +package eventDemo.business.command.command -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import eventDemo.libs.command.CommandId import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/eventDemo/app/command/command/IWantToJoinTheGameCommand.kt b/src/main/kotlin/eventDemo/business/command/command/IWantToJoinTheGameCommand.kt similarity index 77% rename from src/main/kotlin/eventDemo/app/command/command/IWantToJoinTheGameCommand.kt rename to src/main/kotlin/eventDemo/business/command/command/IWantToJoinTheGameCommand.kt index 399215c..e5495d1 100644 --- a/src/main/kotlin/eventDemo/app/command/command/IWantToJoinTheGameCommand.kt +++ b/src/main/kotlin/eventDemo/business/command/command/IWantToJoinTheGameCommand.kt @@ -1,7 +1,7 @@ -package eventDemo.app.command.command +package eventDemo.business.command.command -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import eventDemo.libs.command.CommandId import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/eventDemo/app/command/command/IWantToPlayCardCommand.kt b/src/main/kotlin/eventDemo/business/command/command/IWantToPlayCardCommand.kt similarity index 73% rename from src/main/kotlin/eventDemo/app/command/command/IWantToPlayCardCommand.kt rename to src/main/kotlin/eventDemo/business/command/command/IWantToPlayCardCommand.kt index f146e36..3f1ee52 100644 --- a/src/main/kotlin/eventDemo/app/command/command/IWantToPlayCardCommand.kt +++ b/src/main/kotlin/eventDemo/business/command/command/IWantToPlayCardCommand.kt @@ -1,8 +1,8 @@ -package eventDemo.app.command.command +package eventDemo.business.command.command -import eventDemo.app.entity.Card -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.Card +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import eventDemo.libs.command.CommandId import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/eventDemo/app/command/command/IamReadyToPlayCommand.kt b/src/main/kotlin/eventDemo/business/command/command/IamReadyToPlayCommand.kt similarity index 76% rename from src/main/kotlin/eventDemo/app/command/command/IamReadyToPlayCommand.kt rename to src/main/kotlin/eventDemo/business/command/command/IamReadyToPlayCommand.kt index a2596b9..467712a 100644 --- a/src/main/kotlin/eventDemo/app/command/command/IamReadyToPlayCommand.kt +++ b/src/main/kotlin/eventDemo/business/command/command/IamReadyToPlayCommand.kt @@ -1,7 +1,7 @@ -package eventDemo.app.command.command +package eventDemo.business.command.command -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import eventDemo.libs.command.CommandId import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/eventDemo/app/entity/Card.kt b/src/main/kotlin/eventDemo/business/entity/Card.kt similarity index 98% rename from src/main/kotlin/eventDemo/app/entity/Card.kt rename to src/main/kotlin/eventDemo/business/entity/Card.kt index e8f49f2..93952c6 100644 --- a/src/main/kotlin/eventDemo/app/entity/Card.kt +++ b/src/main/kotlin/eventDemo/business/entity/Card.kt @@ -1,4 +1,4 @@ -package eventDemo.app.entity +package eventDemo.business.entity import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.SerialName diff --git a/src/main/kotlin/eventDemo/app/entity/Deck.kt b/src/main/kotlin/eventDemo/business/entity/Deck.kt similarity index 99% rename from src/main/kotlin/eventDemo/app/entity/Deck.kt rename to src/main/kotlin/eventDemo/business/entity/Deck.kt index 0ac55a2..a282dcf 100644 --- a/src/main/kotlin/eventDemo/app/entity/Deck.kt +++ b/src/main/kotlin/eventDemo/business/entity/Deck.kt @@ -1,4 +1,4 @@ -package eventDemo.app.entity +package eventDemo.business.entity import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/eventDemo/app/entity/GameId.kt b/src/main/kotlin/eventDemo/business/entity/GameId.kt similarity index 91% rename from src/main/kotlin/eventDemo/app/entity/GameId.kt rename to src/main/kotlin/eventDemo/business/entity/GameId.kt index dd1c11c..366ed83 100644 --- a/src/main/kotlin/eventDemo/app/entity/GameId.kt +++ b/src/main/kotlin/eventDemo/business/entity/GameId.kt @@ -1,4 +1,4 @@ -package eventDemo.app.entity +package eventDemo.business.entity import eventDemo.configuration.GameIdSerializer import eventDemo.libs.event.AggregateId diff --git a/src/main/kotlin/eventDemo/app/entity/Player.kt b/src/main/kotlin/eventDemo/business/entity/Player.kt similarity index 95% rename from src/main/kotlin/eventDemo/app/entity/Player.kt rename to src/main/kotlin/eventDemo/business/entity/Player.kt index 76f3cfe..97cab7a 100644 --- a/src/main/kotlin/eventDemo/app/entity/Player.kt +++ b/src/main/kotlin/eventDemo/business/entity/Player.kt @@ -1,4 +1,4 @@ -package eventDemo.app.entity +package eventDemo.business.entity import eventDemo.configuration.PlayerIdSerializer import eventDemo.configuration.UUIDSerializer diff --git a/src/main/kotlin/eventDemo/app/entity/PlayersHands.kt b/src/main/kotlin/eventDemo/business/entity/PlayersHands.kt similarity index 97% rename from src/main/kotlin/eventDemo/app/entity/PlayersHands.kt rename to src/main/kotlin/eventDemo/business/entity/PlayersHands.kt index 96afccc..bf39119 100644 --- a/src/main/kotlin/eventDemo/app/entity/PlayersHands.kt +++ b/src/main/kotlin/eventDemo/business/entity/PlayersHands.kt @@ -1,4 +1,4 @@ -package eventDemo.app.entity +package eventDemo.business.entity import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/eventDemo/app/event/EventHandler.kt b/src/main/kotlin/eventDemo/business/event/EventHandler.kt similarity index 74% rename from src/main/kotlin/eventDemo/app/event/EventHandler.kt rename to src/main/kotlin/eventDemo/business/event/EventHandler.kt index 458f306..178afd9 100644 --- a/src/main/kotlin/eventDemo/app/event/EventHandler.kt +++ b/src/main/kotlin/eventDemo/business/event/EventHandler.kt @@ -1,4 +1,4 @@ -package eventDemo.app.event +package eventDemo.business.event import eventDemo.libs.event.AggregateId import eventDemo.libs.event.Event @@ -7,7 +7,7 @@ import eventDemo.libs.event.Event * A stream to publish and read the played card event. */ interface EventHandler, ID : AggregateId> { - fun registerProjectionBuilder(builder: (E) -> Unit) + fun registerProjectionBuilder(builder: (event: E) -> Unit) fun handle( aggregateId: ID, diff --git a/src/main/kotlin/eventDemo/business/event/GameEventBus.kt b/src/main/kotlin/eventDemo/business/event/GameEventBus.kt new file mode 100644 index 0000000..a9e010e --- /dev/null +++ b/src/main/kotlin/eventDemo/business/event/GameEventBus.kt @@ -0,0 +1,7 @@ +package eventDemo.business.event + +import eventDemo.business.entity.GameId +import eventDemo.business.event.event.GameEvent +import eventDemo.libs.event.EventBus + +interface GameEventBus : EventBus diff --git a/src/main/kotlin/eventDemo/app/event/GameEventHandler.kt b/src/main/kotlin/eventDemo/business/event/GameEventHandler.kt similarity index 88% rename from src/main/kotlin/eventDemo/app/event/GameEventHandler.kt rename to src/main/kotlin/eventDemo/business/event/GameEventHandler.kt index bddac82..757e6f3 100644 --- a/src/main/kotlin/eventDemo/app/event/GameEventHandler.kt +++ b/src/main/kotlin/eventDemo/business/event/GameEventHandler.kt @@ -1,7 +1,7 @@ -package eventDemo.app.event +package eventDemo.business.event -import eventDemo.app.entity.GameId -import eventDemo.app.event.event.GameEvent +import eventDemo.business.entity.GameId +import eventDemo.business.event.event.GameEvent import eventDemo.libs.event.VersionBuilder import io.github.oshai.kotlinlogging.withLoggingContext import java.util.concurrent.ConcurrentHashMap @@ -20,7 +20,7 @@ class GameEventHandler( private val projectionsBuilders: ConcurrentLinkedQueue<(GameEvent) -> Unit> = ConcurrentLinkedQueue() private val locks: ConcurrentHashMap = ConcurrentHashMap() - override fun registerProjectionBuilder(builder: GameProjectionBuilder) { + override fun registerProjectionBuilder(builder: (event: GameEvent) -> Unit) { projectionsBuilders.add(builder) } @@ -55,5 +55,3 @@ class GameEventHandler( } } } - -typealias GameProjectionBuilder = (GameEvent) -> Unit diff --git a/src/main/kotlin/eventDemo/business/event/GameEventStore.kt b/src/main/kotlin/eventDemo/business/event/GameEventStore.kt new file mode 100644 index 0000000..7354184 --- /dev/null +++ b/src/main/kotlin/eventDemo/business/event/GameEventStore.kt @@ -0,0 +1,7 @@ +package eventDemo.business.event + +import eventDemo.business.entity.GameId +import eventDemo.business.event.event.GameEvent +import eventDemo.libs.event.EventStore + +interface GameEventStore : EventStore diff --git a/src/main/kotlin/eventDemo/app/event/event/CardIsPlayedEvent.kt b/src/main/kotlin/eventDemo/business/event/event/CardIsPlayedEvent.kt similarity index 73% rename from src/main/kotlin/eventDemo/app/event/event/CardIsPlayedEvent.kt rename to src/main/kotlin/eventDemo/business/event/event/CardIsPlayedEvent.kt index 827adcf..1c80a91 100644 --- a/src/main/kotlin/eventDemo/app/event/event/CardIsPlayedEvent.kt +++ b/src/main/kotlin/eventDemo/business/event/event/CardIsPlayedEvent.kt @@ -1,8 +1,8 @@ -package eventDemo.app.event.event +package eventDemo.business.event.event -import eventDemo.app.entity.Card -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.Card +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import kotlinx.datetime.Clock import kotlinx.datetime.Instant import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/event/event/GameEvent.kt b/src/main/kotlin/eventDemo/business/event/event/GameEvent.kt similarity index 78% rename from src/main/kotlin/eventDemo/app/event/event/GameEvent.kt rename to src/main/kotlin/eventDemo/business/event/event/GameEvent.kt index 89cebe2..39fb2bb 100644 --- a/src/main/kotlin/eventDemo/app/event/event/GameEvent.kt +++ b/src/main/kotlin/eventDemo/business/event/event/GameEvent.kt @@ -1,6 +1,6 @@ -package eventDemo.app.event.event +package eventDemo.business.event.event -import eventDemo.app.entity.GameId +import eventDemo.business.entity.GameId import eventDemo.libs.event.Event import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/event/event/GameStartedEvent.kt b/src/main/kotlin/eventDemo/business/event/event/GameStartedEvent.kt similarity index 83% rename from src/main/kotlin/eventDemo/app/event/event/GameStartedEvent.kt rename to src/main/kotlin/eventDemo/business/event/event/GameStartedEvent.kt index c32e382..1dd2f81 100644 --- a/src/main/kotlin/eventDemo/app/event/event/GameStartedEvent.kt +++ b/src/main/kotlin/eventDemo/business/event/event/GameStartedEvent.kt @@ -1,9 +1,9 @@ -package eventDemo.app.event.event +package eventDemo.business.event.event -import eventDemo.app.entity.Deck -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player -import eventDemo.app.entity.initHands +import eventDemo.business.entity.Deck +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player +import eventDemo.business.entity.initHands import kotlinx.datetime.Clock import kotlinx.datetime.Instant import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/event/event/NewPlayerEvent.kt b/src/main/kotlin/eventDemo/business/event/event/NewPlayerEvent.kt similarity index 76% rename from src/main/kotlin/eventDemo/app/event/event/NewPlayerEvent.kt rename to src/main/kotlin/eventDemo/business/event/event/NewPlayerEvent.kt index 437e38f..852d2c9 100644 --- a/src/main/kotlin/eventDemo/app/event/event/NewPlayerEvent.kt +++ b/src/main/kotlin/eventDemo/business/event/event/NewPlayerEvent.kt @@ -1,7 +1,7 @@ -package eventDemo.app.event.event +package eventDemo.business.event.event -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import kotlinx.datetime.Clock import kotlinx.datetime.Instant import java.util.UUID diff --git a/src/main/kotlin/eventDemo/business/event/event/PlayerActionEvent.kt b/src/main/kotlin/eventDemo/business/event/event/PlayerActionEvent.kt new file mode 100644 index 0000000..0c26b54 --- /dev/null +++ b/src/main/kotlin/eventDemo/business/event/event/PlayerActionEvent.kt @@ -0,0 +1,7 @@ +package eventDemo.business.event.event + +import eventDemo.business.entity.Player + +sealed interface PlayerActionEvent : GameEvent { + val player: Player +} diff --git a/src/main/kotlin/eventDemo/app/event/event/PlayerChoseColorEvent.kt b/src/main/kotlin/eventDemo/business/event/event/PlayerChoseColorEvent.kt similarity index 74% rename from src/main/kotlin/eventDemo/app/event/event/PlayerChoseColorEvent.kt rename to src/main/kotlin/eventDemo/business/event/event/PlayerChoseColorEvent.kt index d2f5376..077a7bb 100644 --- a/src/main/kotlin/eventDemo/app/event/event/PlayerChoseColorEvent.kt +++ b/src/main/kotlin/eventDemo/business/event/event/PlayerChoseColorEvent.kt @@ -1,8 +1,8 @@ -package eventDemo.app.event.event +package eventDemo.business.event.event -import eventDemo.app.entity.Card -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.Card +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import kotlinx.datetime.Clock import kotlinx.datetime.Instant import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/event/event/PlayerHavePassEvent.kt b/src/main/kotlin/eventDemo/business/event/event/PlayerHavePassEvent.kt similarity index 73% rename from src/main/kotlin/eventDemo/app/event/event/PlayerHavePassEvent.kt rename to src/main/kotlin/eventDemo/business/event/event/PlayerHavePassEvent.kt index 54bbbf3..aa9ba75 100644 --- a/src/main/kotlin/eventDemo/app/event/event/PlayerHavePassEvent.kt +++ b/src/main/kotlin/eventDemo/business/event/event/PlayerHavePassEvent.kt @@ -1,8 +1,8 @@ -package eventDemo.app.event.event +package eventDemo.business.event.event -import eventDemo.app.entity.Card -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.Card +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import kotlinx.datetime.Clock import kotlinx.datetime.Instant import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/event/event/PlayerReadyEvent.kt b/src/main/kotlin/eventDemo/business/event/event/PlayerReadyEvent.kt similarity index 76% rename from src/main/kotlin/eventDemo/app/event/event/PlayerReadyEvent.kt rename to src/main/kotlin/eventDemo/business/event/event/PlayerReadyEvent.kt index da2fd24..b744323 100644 --- a/src/main/kotlin/eventDemo/app/event/event/PlayerReadyEvent.kt +++ b/src/main/kotlin/eventDemo/business/event/event/PlayerReadyEvent.kt @@ -1,7 +1,7 @@ -package eventDemo.app.event.event +package eventDemo.business.event.event -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import kotlinx.datetime.Clock import kotlinx.datetime.Instant import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/event/event/PlayerWinEvent.kt b/src/main/kotlin/eventDemo/business/event/event/PlayerWinEvent.kt similarity index 76% rename from src/main/kotlin/eventDemo/app/event/event/PlayerWinEvent.kt rename to src/main/kotlin/eventDemo/business/event/event/PlayerWinEvent.kt index b233d39..f2dbf36 100644 --- a/src/main/kotlin/eventDemo/app/event/event/PlayerWinEvent.kt +++ b/src/main/kotlin/eventDemo/business/event/event/PlayerWinEvent.kt @@ -1,7 +1,7 @@ -package eventDemo.app.event.event +package eventDemo.business.event.event -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import kotlinx.datetime.Clock import kotlinx.datetime.Instant import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/eventListener/PlayerNotificationEventListener.kt b/src/main/kotlin/eventDemo/business/event/eventListener/PlayerNotificationEventListener.kt similarity index 69% rename from src/main/kotlin/eventDemo/app/eventListener/PlayerNotificationEventListener.kt rename to src/main/kotlin/eventDemo/business/event/eventListener/PlayerNotificationEventListener.kt index 1bcc7b7..d76ebbf 100644 --- a/src/main/kotlin/eventDemo/app/eventListener/PlayerNotificationEventListener.kt +++ b/src/main/kotlin/eventDemo/business/event/eventListener/PlayerNotificationEventListener.kt @@ -1,32 +1,30 @@ -package eventDemo.app.eventListener +package eventDemo.business.event.eventListener -import eventDemo.app.entity.Card -import eventDemo.app.entity.Player -import eventDemo.app.event.GameEventBus -import eventDemo.app.event.event.CardIsPlayedEvent -import eventDemo.app.event.event.GameEvent -import eventDemo.app.event.event.GameStartedEvent -import eventDemo.app.event.event.NewPlayerEvent -import eventDemo.app.event.event.PlayerChoseColorEvent -import eventDemo.app.event.event.PlayerHavePassEvent -import eventDemo.app.event.event.PlayerReadyEvent -import eventDemo.app.event.event.PlayerWinEvent -import eventDemo.app.event.projection.GameStateRepository -import eventDemo.app.notification.ItsTheTurnOfNotification -import eventDemo.app.notification.Notification -import eventDemo.app.notification.PlayerAsJoinTheGameNotification -import eventDemo.app.notification.PlayerAsPlayACardNotification -import eventDemo.app.notification.PlayerHavePassNotification -import eventDemo.app.notification.PlayerWasChoseTheCardColorNotification -import eventDemo.app.notification.PlayerWasReadyNotification -import eventDemo.app.notification.PlayerWinNotification -import eventDemo.app.notification.TheGameWasStartedNotification -import eventDemo.app.notification.WelcomeToTheGameNotification -import eventDemo.app.notification.YourNewCardNotification +import eventDemo.business.entity.Card +import eventDemo.business.entity.Player +import eventDemo.business.event.GameEventBus +import eventDemo.business.event.event.CardIsPlayedEvent +import eventDemo.business.event.event.GameEvent +import eventDemo.business.event.event.GameStartedEvent +import eventDemo.business.event.event.NewPlayerEvent +import eventDemo.business.event.event.PlayerChoseColorEvent +import eventDemo.business.event.event.PlayerHavePassEvent +import eventDemo.business.event.event.PlayerReadyEvent +import eventDemo.business.event.event.PlayerWinEvent +import eventDemo.business.event.projection.GameStateRepository +import eventDemo.business.notification.ItsTheTurnOfNotification +import eventDemo.business.notification.Notification +import eventDemo.business.notification.PlayerAsJoinTheGameNotification +import eventDemo.business.notification.PlayerAsPlayACardNotification +import eventDemo.business.notification.PlayerHavePassNotification +import eventDemo.business.notification.PlayerWasChoseTheCardColorNotification +import eventDemo.business.notification.PlayerWasReadyNotification +import eventDemo.business.notification.PlayerWinNotification +import eventDemo.business.notification.TheGameWasStartedNotification +import eventDemo.business.notification.WelcomeToTheGameNotification +import eventDemo.business.notification.YourNewCardNotification import io.github.oshai.kotlinlogging.KotlinLogging import io.github.oshai.kotlinlogging.withLoggingContext -import kotlinx.coroutines.channels.SendChannel -import kotlinx.coroutines.channels.trySendBlocking class PlayerNotificationEventListener( private val eventBus: GameEventBus, @@ -35,7 +33,7 @@ class PlayerNotificationEventListener( private val logger = KotlinLogging.logger {} fun startListening( - outgoingNotificationChannel: SendChannel, + outgoingNotification: (Notification) -> Unit, currentPlayer: Player, ) { eventBus.subscribe { event: GameEvent -> @@ -46,7 +44,7 @@ class PlayerNotificationEventListener( withLoggingContext("notification" to this.toString()) { if (currentState.players.contains(currentPlayer)) { // Only notify players who have already joined the game. - outgoingNotificationChannel.trySendBlocking(this) + outgoingNotification(this) logger.info { "Notification was SEND" } } else { // Rare use case, when a connexion is created with the channel, diff --git a/src/main/kotlin/eventDemo/app/eventListener/ReactionEventListener.kt b/src/main/kotlin/eventDemo/business/event/eventListener/ReactionEventListener.kt similarity index 79% rename from src/main/kotlin/eventDemo/app/eventListener/ReactionEventListener.kt rename to src/main/kotlin/eventDemo/business/event/eventListener/ReactionEventListener.kt index a662aaa..a564015 100644 --- a/src/main/kotlin/eventDemo/app/eventListener/ReactionEventListener.kt +++ b/src/main/kotlin/eventDemo/business/event/eventListener/ReactionEventListener.kt @@ -1,13 +1,13 @@ -package eventDemo.app.eventListener +package eventDemo.business.event.eventListener -import eventDemo.app.event.GameEventBus -import eventDemo.app.event.GameEventHandler -import eventDemo.app.event.event.GameEvent -import eventDemo.app.event.event.GameStartedEvent -import eventDemo.app.event.event.PlayerReadyEvent -import eventDemo.app.event.event.PlayerWinEvent -import eventDemo.app.event.projection.GameState -import eventDemo.app.event.projection.GameStateRepository +import eventDemo.business.event.GameEventBus +import eventDemo.business.event.GameEventHandler +import eventDemo.business.event.event.GameEvent +import eventDemo.business.event.event.GameStartedEvent +import eventDemo.business.event.event.PlayerReadyEvent +import eventDemo.business.event.event.PlayerWinEvent +import eventDemo.business.event.projection.GameState +import eventDemo.business.event.projection.GameStateRepository import io.github.oshai.kotlinlogging.KotlinLogging import io.github.oshai.kotlinlogging.withLoggingContext diff --git a/src/main/kotlin/eventDemo/app/event/projection/GameState.kt b/src/main/kotlin/eventDemo/business/event/projection/GameState.kt similarity index 95% rename from src/main/kotlin/eventDemo/app/event/projection/GameState.kt rename to src/main/kotlin/eventDemo/business/event/projection/GameState.kt index 108d7cb..840343a 100644 --- a/src/main/kotlin/eventDemo/app/event/projection/GameState.kt +++ b/src/main/kotlin/eventDemo/business/event/projection/GameState.kt @@ -1,9 +1,9 @@ -package eventDemo.app.event.projection +package eventDemo.business.event.projection -import eventDemo.app.entity.Card -import eventDemo.app.entity.Deck -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.Card +import eventDemo.business.entity.Deck +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import kotlinx.serialization.Serializable @Serializable diff --git a/src/main/kotlin/eventDemo/app/event/projection/GameStateBuilder.kt b/src/main/kotlin/eventDemo/business/event/projection/GameStateBuilder.kt similarity index 83% rename from src/main/kotlin/eventDemo/app/event/projection/GameStateBuilder.kt rename to src/main/kotlin/eventDemo/business/event/projection/GameStateBuilder.kt index 9bfd8fb..1ffa802 100644 --- a/src/main/kotlin/eventDemo/app/event/projection/GameStateBuilder.kt +++ b/src/main/kotlin/eventDemo/business/event/projection/GameStateBuilder.kt @@ -1,15 +1,15 @@ -package eventDemo.app.event.projection +package eventDemo.business.event.projection -import eventDemo.app.entity.Card -import eventDemo.app.event.event.CardIsPlayedEvent -import eventDemo.app.event.event.GameEvent -import eventDemo.app.event.event.GameStartedEvent -import eventDemo.app.event.event.NewPlayerEvent -import eventDemo.app.event.event.PlayerActionEvent -import eventDemo.app.event.event.PlayerChoseColorEvent -import eventDemo.app.event.event.PlayerHavePassEvent -import eventDemo.app.event.event.PlayerReadyEvent -import eventDemo.app.event.event.PlayerWinEvent +import eventDemo.business.entity.Card +import eventDemo.business.event.event.CardIsPlayedEvent +import eventDemo.business.event.event.GameEvent +import eventDemo.business.event.event.GameStartedEvent +import eventDemo.business.event.event.NewPlayerEvent +import eventDemo.business.event.event.PlayerActionEvent +import eventDemo.business.event.event.PlayerChoseColorEvent +import eventDemo.business.event.event.PlayerHavePassEvent +import eventDemo.business.event.event.PlayerReadyEvent +import eventDemo.business.event.event.PlayerWinEvent import io.github.oshai.kotlinlogging.KotlinLogging fun GameState.apply(event: GameEvent): GameState = diff --git a/src/main/kotlin/eventDemo/business/event/projection/GameStateRepository.kt b/src/main/kotlin/eventDemo/business/event/projection/GameStateRepository.kt new file mode 100644 index 0000000..5637924 --- /dev/null +++ b/src/main/kotlin/eventDemo/business/event/projection/GameStateRepository.kt @@ -0,0 +1,10 @@ +package eventDemo.business.event.projection + +import eventDemo.business.entity.GameId +import eventDemo.business.event.event.GameEvent + +interface GameStateRepository { + fun getLast(gameId: GameId): GameState + + fun getUntil(event: GameEvent): GameState +} diff --git a/src/main/kotlin/eventDemo/app/event/projection/Projection.kt b/src/main/kotlin/eventDemo/business/event/projection/Projection.kt similarity index 75% rename from src/main/kotlin/eventDemo/app/event/projection/Projection.kt rename to src/main/kotlin/eventDemo/business/event/projection/Projection.kt index 4e0be8e..c6d255b 100644 --- a/src/main/kotlin/eventDemo/app/event/projection/Projection.kt +++ b/src/main/kotlin/eventDemo/business/event/projection/Projection.kt @@ -1,4 +1,4 @@ -package eventDemo.app.event.projection +package eventDemo.business.event.projection import eventDemo.libs.event.AggregateId diff --git a/src/main/kotlin/eventDemo/app/notification/CommandErrorNotification.kt b/src/main/kotlin/eventDemo/business/notification/CommandErrorNotification.kt similarity index 90% rename from src/main/kotlin/eventDemo/app/notification/CommandErrorNotification.kt rename to src/main/kotlin/eventDemo/business/notification/CommandErrorNotification.kt index fd0ba31..74701ad 100644 --- a/src/main/kotlin/eventDemo/app/notification/CommandErrorNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/CommandErrorNotification.kt @@ -1,4 +1,4 @@ -package eventDemo.app.notification +package eventDemo.business.notification import eventDemo.configuration.UUIDSerializer import eventDemo.libs.command.Command diff --git a/src/main/kotlin/eventDemo/app/notification/CommandNotification.kt b/src/main/kotlin/eventDemo/business/notification/CommandNotification.kt similarity index 56% rename from src/main/kotlin/eventDemo/app/notification/CommandNotification.kt rename to src/main/kotlin/eventDemo/business/notification/CommandNotification.kt index 9d5b166..86778fc 100644 --- a/src/main/kotlin/eventDemo/app/notification/CommandNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/CommandNotification.kt @@ -1,3 +1,3 @@ -package eventDemo.app.notification +package eventDemo.business.notification sealed interface CommandNotification : Notification diff --git a/src/main/kotlin/eventDemo/app/notification/CommandSuccessNotification.kt b/src/main/kotlin/eventDemo/business/notification/CommandSuccessNotification.kt similarity index 90% rename from src/main/kotlin/eventDemo/app/notification/CommandSuccessNotification.kt rename to src/main/kotlin/eventDemo/business/notification/CommandSuccessNotification.kt index 5dd92d4..20cc95b 100644 --- a/src/main/kotlin/eventDemo/app/notification/CommandSuccessNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/CommandSuccessNotification.kt @@ -1,4 +1,4 @@ -package eventDemo.app.notification +package eventDemo.business.notification import eventDemo.configuration.UUIDSerializer import eventDemo.libs.command.CommandId diff --git a/src/main/kotlin/eventDemo/app/notification/ItsTheTurnOfNotification.kt b/src/main/kotlin/eventDemo/business/notification/ItsTheTurnOfNotification.kt similarity index 78% rename from src/main/kotlin/eventDemo/app/notification/ItsTheTurnOfNotification.kt rename to src/main/kotlin/eventDemo/business/notification/ItsTheTurnOfNotification.kt index 98df5a9..2556070 100644 --- a/src/main/kotlin/eventDemo/app/notification/ItsTheTurnOfNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/ItsTheTurnOfNotification.kt @@ -1,6 +1,6 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Player +import eventDemo.business.entity.Player import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/notification/Notification.kt b/src/main/kotlin/eventDemo/business/notification/Notification.kt similarity index 84% rename from src/main/kotlin/eventDemo/app/notification/Notification.kt rename to src/main/kotlin/eventDemo/business/notification/Notification.kt index ad992c3..2b8c078 100644 --- a/src/main/kotlin/eventDemo/app/notification/Notification.kt +++ b/src/main/kotlin/eventDemo/business/notification/Notification.kt @@ -1,4 +1,4 @@ -package eventDemo.app.notification +package eventDemo.business.notification import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/eventDemo/app/notification/PlayerAsJoinTheGameNotification.kt b/src/main/kotlin/eventDemo/business/notification/PlayerAsJoinTheGameNotification.kt similarity index 78% rename from src/main/kotlin/eventDemo/app/notification/PlayerAsJoinTheGameNotification.kt rename to src/main/kotlin/eventDemo/business/notification/PlayerAsJoinTheGameNotification.kt index cb1e5f6..6c4fd36 100644 --- a/src/main/kotlin/eventDemo/app/notification/PlayerAsJoinTheGameNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/PlayerAsJoinTheGameNotification.kt @@ -1,6 +1,6 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Player +import eventDemo.business.entity.Player import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/notification/PlayerAsPlayACardNotification.kt b/src/main/kotlin/eventDemo/business/notification/PlayerAsPlayACardNotification.kt similarity index 72% rename from src/main/kotlin/eventDemo/app/notification/PlayerAsPlayACardNotification.kt rename to src/main/kotlin/eventDemo/business/notification/PlayerAsPlayACardNotification.kt index 19c3a99..348722a 100644 --- a/src/main/kotlin/eventDemo/app/notification/PlayerAsPlayACardNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/PlayerAsPlayACardNotification.kt @@ -1,7 +1,7 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Card -import eventDemo.app.entity.Player +import eventDemo.business.entity.Card +import eventDemo.business.entity.Player import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/notification/PlayerHavePassNotification.kt b/src/main/kotlin/eventDemo/business/notification/PlayerHavePassNotification.kt similarity index 78% rename from src/main/kotlin/eventDemo/app/notification/PlayerHavePassNotification.kt rename to src/main/kotlin/eventDemo/business/notification/PlayerHavePassNotification.kt index e681b52..8dadbb0 100644 --- a/src/main/kotlin/eventDemo/app/notification/PlayerHavePassNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/PlayerHavePassNotification.kt @@ -1,6 +1,6 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Player +import eventDemo.business.entity.Player import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/notification/PlayerWasChoseTheCardColorNotification.kt b/src/main/kotlin/eventDemo/business/notification/PlayerWasChoseTheCardColorNotification.kt similarity index 73% rename from src/main/kotlin/eventDemo/app/notification/PlayerWasChoseTheCardColorNotification.kt rename to src/main/kotlin/eventDemo/business/notification/PlayerWasChoseTheCardColorNotification.kt index b7c637a..56bc30a 100644 --- a/src/main/kotlin/eventDemo/app/notification/PlayerWasChoseTheCardColorNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/PlayerWasChoseTheCardColorNotification.kt @@ -1,7 +1,7 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Card -import eventDemo.app.entity.Player +import eventDemo.business.entity.Card +import eventDemo.business.entity.Player import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/notification/PlayerWasReadyNotification.kt b/src/main/kotlin/eventDemo/business/notification/PlayerWasReadyNotification.kt similarity index 78% rename from src/main/kotlin/eventDemo/app/notification/PlayerWasReadyNotification.kt rename to src/main/kotlin/eventDemo/business/notification/PlayerWasReadyNotification.kt index 789873a..b5be34f 100644 --- a/src/main/kotlin/eventDemo/app/notification/PlayerWasReadyNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/PlayerWasReadyNotification.kt @@ -1,6 +1,6 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Player +import eventDemo.business.entity.Player import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/notification/PlayerWinNotification.kt b/src/main/kotlin/eventDemo/business/notification/PlayerWinNotification.kt similarity index 78% rename from src/main/kotlin/eventDemo/app/notification/PlayerWinNotification.kt rename to src/main/kotlin/eventDemo/business/notification/PlayerWinNotification.kt index d4cb29b..ad065a0 100644 --- a/src/main/kotlin/eventDemo/app/notification/PlayerWinNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/PlayerWinNotification.kt @@ -1,6 +1,6 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Player +import eventDemo.business.entity.Player import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/notification/TheGameWasStartedNotification.kt b/src/main/kotlin/eventDemo/business/notification/TheGameWasStartedNotification.kt similarity index 79% rename from src/main/kotlin/eventDemo/app/notification/TheGameWasStartedNotification.kt rename to src/main/kotlin/eventDemo/business/notification/TheGameWasStartedNotification.kt index b551290..2d34dde 100644 --- a/src/main/kotlin/eventDemo/app/notification/TheGameWasStartedNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/TheGameWasStartedNotification.kt @@ -1,6 +1,6 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Card +import eventDemo.business.entity.Card import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/notification/WelcomeToTheGameNotification.kt b/src/main/kotlin/eventDemo/business/notification/WelcomeToTheGameNotification.kt similarity index 79% rename from src/main/kotlin/eventDemo/app/notification/WelcomeToTheGameNotification.kt rename to src/main/kotlin/eventDemo/business/notification/WelcomeToTheGameNotification.kt index 66ed102..b883597 100644 --- a/src/main/kotlin/eventDemo/app/notification/WelcomeToTheGameNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/WelcomeToTheGameNotification.kt @@ -1,6 +1,6 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Player +import eventDemo.business.entity.Player import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/app/notification/YourNewCardNotification.kt b/src/main/kotlin/eventDemo/business/notification/YourNewCardNotification.kt similarity index 78% rename from src/main/kotlin/eventDemo/app/notification/YourNewCardNotification.kt rename to src/main/kotlin/eventDemo/business/notification/YourNewCardNotification.kt index a02150f..d15c2a2 100644 --- a/src/main/kotlin/eventDemo/app/notification/YourNewCardNotification.kt +++ b/src/main/kotlin/eventDemo/business/notification/YourNewCardNotification.kt @@ -1,6 +1,6 @@ -package eventDemo.app.notification +package eventDemo.business.notification -import eventDemo.app.entity.Card +import eventDemo.business.entity.Card import eventDemo.configuration.UUIDSerializer import kotlinx.serialization.Serializable import java.util.UUID diff --git a/src/main/kotlin/eventDemo/configuration/ConfigureAuth.kt b/src/main/kotlin/eventDemo/configuration/ConfigureAuth.kt index 2907ccb..362ea00 100644 --- a/src/main/kotlin/eventDemo/configuration/ConfigureAuth.kt +++ b/src/main/kotlin/eventDemo/configuration/ConfigureAuth.kt @@ -2,7 +2,7 @@ package eventDemo.configuration import com.auth0.jwt.JWT import com.auth0.jwt.algorithms.Algorithm -import eventDemo.app.entity.Player +import eventDemo.business.entity.Player import io.ktor.http.HttpStatusCode import io.ktor.server.application.Application import io.ktor.server.application.call diff --git a/src/main/kotlin/eventDemo/configuration/ConfigureDI.kt b/src/main/kotlin/eventDemo/configuration/ConfigureDI.kt index b3a29a5..6e93e8a 100644 --- a/src/main/kotlin/eventDemo/configuration/ConfigureDI.kt +++ b/src/main/kotlin/eventDemo/configuration/ConfigureDI.kt @@ -1,20 +1,21 @@ package eventDemo.configuration -import eventDemo.app.command.GameCommandActionRunner -import eventDemo.app.command.GameCommandHandler -import eventDemo.app.command.command.GameCommand -import eventDemo.app.event.GameEventBus -import eventDemo.app.event.GameEventHandler -import eventDemo.app.event.GameEventStore -import eventDemo.app.event.projection.GameStateRepository -import eventDemo.app.event.projection.SnapshotConfig -import eventDemo.app.eventListener.PlayerNotificationEventListener +import eventDemo.adapter.infrastructureLayer.event.GameEventBusInMemory +import eventDemo.adapter.infrastructureLayer.event.GameEventStoreInMemory +import eventDemo.adapter.infrastructureLayer.event.projection.GameStateRepositoryInMemory +import eventDemo.business.command.GameCommandActionRunner +import eventDemo.business.command.GameCommandHandler +import eventDemo.business.command.command.GameCommand +import eventDemo.business.event.GameEventBus +import eventDemo.business.event.GameEventHandler +import eventDemo.business.event.GameEventStore +import eventDemo.business.event.eventListener.PlayerNotificationEventListener +import eventDemo.business.event.projection.GameStateRepository import eventDemo.libs.command.CommandRunnerController import eventDemo.libs.command.CommandStreamChannel -import eventDemo.libs.event.EventBusInMemory -import eventDemo.libs.event.EventStoreInMemory import eventDemo.libs.event.VersionBuilder import eventDemo.libs.event.VersionBuilderLocal +import eventDemo.libs.event.projection.SnapshotConfig import io.ktor.server.application.Application import io.ktor.server.application.install import org.koin.core.module.dsl.singleOf @@ -33,14 +34,17 @@ fun Application.configureKoin() { val appKoinModule = module { single { - GameEventBus(EventBusInMemory()) - } + GameEventBusInMemory() + } bind GameEventBus::class + single { - GameEventStore(EventStoreInMemory()) - } + GameEventStoreInMemory() + } bind GameEventStore::class + single { - GameStateRepository(get(), get(), snapshotConfig = SnapshotConfig()) - } + GameStateRepositoryInMemory(get(), get(), snapshotConfig = SnapshotConfig()) + } bind GameStateRepository::class + single { CommandStreamChannel(get()) } diff --git a/src/main/kotlin/eventDemo/configuration/ConfigureDIAction.kt b/src/main/kotlin/eventDemo/configuration/ConfigureDIAction.kt index f877a8e..fbfe9e0 100644 --- a/src/main/kotlin/eventDemo/configuration/ConfigureDIAction.kt +++ b/src/main/kotlin/eventDemo/configuration/ConfigureDIAction.kt @@ -1,9 +1,9 @@ package eventDemo.configuration -import eventDemo.app.command.action.ICantPlay -import eventDemo.app.command.action.IWantToJoinTheGame -import eventDemo.app.command.action.IWantToPlayCard -import eventDemo.app.command.action.IamReadyToPlay +import eventDemo.business.command.action.ICantPlay +import eventDemo.business.command.action.IWantToJoinTheGame +import eventDemo.business.command.action.IWantToPlayCard +import eventDemo.business.command.action.IamReadyToPlay import org.koin.core.module.Module import org.koin.core.module.dsl.singleOf diff --git a/src/main/kotlin/eventDemo/configuration/ConfigureGameListener.kt b/src/main/kotlin/eventDemo/configuration/ConfigureGameListener.kt index 2743be9..d24a64c 100644 --- a/src/main/kotlin/eventDemo/configuration/ConfigureGameListener.kt +++ b/src/main/kotlin/eventDemo/configuration/ConfigureGameListener.kt @@ -1,6 +1,6 @@ package eventDemo.configuration -import eventDemo.app.eventListener.ReactionEventListener +import eventDemo.business.event.eventListener.ReactionEventListener import io.ktor.server.application.Application import org.koin.ktor.ext.get diff --git a/src/main/kotlin/eventDemo/configuration/ConfigureSerialization.kt b/src/main/kotlin/eventDemo/configuration/ConfigureSerialization.kt index 952bc94..b9e302a 100644 --- a/src/main/kotlin/eventDemo/configuration/ConfigureSerialization.kt +++ b/src/main/kotlin/eventDemo/configuration/ConfigureSerialization.kt @@ -1,7 +1,7 @@ package eventDemo.configuration -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player import eventDemo.libs.command.CommandId import io.ktor.serialization.kotlinx.json.json import io.ktor.server.application.Application diff --git a/src/main/kotlin/eventDemo/configuration/DeclareHttpRoutes.kt b/src/main/kotlin/eventDemo/configuration/DeclareHttpRoutes.kt index 61b4aa1..28cbb46 100644 --- a/src/main/kotlin/eventDemo/configuration/DeclareHttpRoutes.kt +++ b/src/main/kotlin/eventDemo/configuration/DeclareHttpRoutes.kt @@ -1,6 +1,6 @@ package eventDemo.configuration -import eventDemo.app.query.readTheGameState +import eventDemo.adapter.interfaceLayer.readTheGameState import io.ktor.server.application.Application import io.ktor.server.routing.routing import org.koin.ktor.ext.get diff --git a/src/main/kotlin/eventDemo/configuration/DeclareWebSocketsGameRoute.kt b/src/main/kotlin/eventDemo/configuration/DeclareWebSocketsGameRoute.kt index e75d3b9..2a81afb 100644 --- a/src/main/kotlin/eventDemo/configuration/DeclareWebSocketsGameRoute.kt +++ b/src/main/kotlin/eventDemo/configuration/DeclareWebSocketsGameRoute.kt @@ -1,8 +1,8 @@ package eventDemo.configuration -import eventDemo.app.command.GameCommandHandler -import eventDemo.app.command.gameWebSocket -import eventDemo.app.eventListener.PlayerNotificationEventListener +import eventDemo.adapter.interfaceLayer.gameWebSocket +import eventDemo.business.command.GameCommandHandler +import eventDemo.business.event.eventListener.PlayerNotificationEventListener import io.ktor.server.application.Application import io.ktor.server.routing.routing import kotlinx.coroutines.DelicateCoroutinesApi diff --git a/src/main/kotlin/eventDemo/app/event/projection/ProjectionSnapshotRepositoryInMemory.kt b/src/main/kotlin/eventDemo/libs/event/projection/ProjectionSnapshotRepositoryInMemory.kt similarity index 97% rename from src/main/kotlin/eventDemo/app/event/projection/ProjectionSnapshotRepositoryInMemory.kt rename to src/main/kotlin/eventDemo/libs/event/projection/ProjectionSnapshotRepositoryInMemory.kt index 2b1c748..fd7d2d8 100644 --- a/src/main/kotlin/eventDemo/app/event/projection/ProjectionSnapshotRepositoryInMemory.kt +++ b/src/main/kotlin/eventDemo/libs/event/projection/ProjectionSnapshotRepositoryInMemory.kt @@ -1,5 +1,6 @@ -package eventDemo.app.event.projection +package eventDemo.libs.event.projection +import eventDemo.business.event.projection.Projection import eventDemo.libs.event.AggregateId import eventDemo.libs.event.Event import eventDemo.libs.event.EventStore @@ -24,7 +25,7 @@ data class SnapshotConfig( class ProjectionSnapshotRepositoryInMemory, P : Projection, ID : AggregateId>( private val eventStore: EventStore, - private val initialStateBuilder: (ID) -> P, + private val initialStateBuilder: (aggregateId: ID) -> P, private val snapshotCacheConfig: SnapshotConfig = SnapshotConfig(), private val applyToProjection: P.(event: E) -> P, ) { diff --git a/src/test/kotlin/eventDemo/Helpers.kt b/src/test/kotlin/eventDemo/Helpers.kt index 900768d..efd577d 100644 --- a/src/test/kotlin/eventDemo/Helpers.kt +++ b/src/test/kotlin/eventDemo/Helpers.kt @@ -1,7 +1,7 @@ package eventDemo -import eventDemo.app.entity.Card -import eventDemo.app.entity.Deck +import eventDemo.business.entity.Card +import eventDemo.business.entity.Deck fun Deck.allCardCount(): Int = stack.size + discard.size + playersHands.values.flatten().size diff --git a/src/test/kotlin/eventDemo/app/command/GameCommandHandlerTest.kt b/src/test/kotlin/eventDemo/app/command/GameCommandHandlerTest.kt index bab1496..e1bb64d 100644 --- a/src/test/kotlin/eventDemo/app/command/GameCommandHandlerTest.kt +++ b/src/test/kotlin/eventDemo/app/command/GameCommandHandlerTest.kt @@ -1,14 +1,15 @@ package eventDemo.app.command -import eventDemo.app.command.command.GameCommand -import eventDemo.app.command.command.IWantToJoinTheGameCommand -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player -import eventDemo.app.eventListener.PlayerNotificationEventListener -import eventDemo.app.eventListener.ReactionEventListener -import eventDemo.app.notification.CommandSuccessNotification -import eventDemo.app.notification.Notification -import eventDemo.app.notification.WelcomeToTheGameNotification +import eventDemo.business.command.GameCommandHandler +import eventDemo.business.command.command.GameCommand +import eventDemo.business.command.command.IWantToJoinTheGameCommand +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player +import eventDemo.business.event.eventListener.PlayerNotificationEventListener +import eventDemo.business.event.eventListener.ReactionEventListener +import eventDemo.business.notification.CommandSuccessNotification +import eventDemo.business.notification.Notification +import eventDemo.business.notification.WelcomeToTheGameNotification import eventDemo.configuration.appKoinModule import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldContain @@ -16,6 +17,7 @@ import io.kotest.matchers.equals.shouldBeEqual import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.trySendBlocking import kotlinx.coroutines.launch import org.koin.dsl.koinApplication import kotlin.test.assertIs @@ -32,7 +34,7 @@ class GameCommandHandlerTest : val channelCommand = Channel(Channel.BUFFERED) val channelNotification = Channel(Channel.BUFFERED) ReactionEventListener(get(), get(), get()).init() - notificationListener.startListening(channelNotification, player) + notificationListener.startListening({ channelNotification.trySendBlocking(it) }, player) GlobalScope.launch { commandHandler.handle(player, channelCommand, channelNotification) diff --git a/src/test/kotlin/eventDemo/app/entity/DeckTest.kt b/src/test/kotlin/eventDemo/app/entity/DeckTest.kt index bf59e86..45ba901 100644 --- a/src/test/kotlin/eventDemo/app/entity/DeckTest.kt +++ b/src/test/kotlin/eventDemo/app/entity/DeckTest.kt @@ -2,6 +2,9 @@ package eventDemo.app.entity import eventDemo.allCardCount import eventDemo.allCards +import eventDemo.business.entity.Deck +import eventDemo.business.entity.Player +import eventDemo.business.entity.initHands import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldBeUnique import io.kotest.matchers.ints.shouldBeExactly diff --git a/src/test/kotlin/eventDemo/app/entity/PlayerHandKtTest.kt b/src/test/kotlin/eventDemo/app/entity/PlayerHandKtTest.kt index 0c84050..61b31ae 100644 --- a/src/test/kotlin/eventDemo/app/entity/PlayerHandKtTest.kt +++ b/src/test/kotlin/eventDemo/app/entity/PlayerHandKtTest.kt @@ -1,5 +1,8 @@ package eventDemo.app.entity +import eventDemo.business.entity.Card +import eventDemo.business.entity.Player +import eventDemo.business.entity.PlayersHands import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.ints.shouldBeExactly import kotlin.test.assertNotNull diff --git a/src/test/kotlin/eventDemo/app/event/projection/GameStateBuilderTest.kt b/src/test/kotlin/eventDemo/app/event/projection/GameStateBuilderTest.kt index 633993b..aac62d3 100644 --- a/src/test/kotlin/eventDemo/app/event/projection/GameStateBuilderTest.kt +++ b/src/test/kotlin/eventDemo/app/event/projection/GameStateBuilderTest.kt @@ -1,13 +1,15 @@ package eventDemo.app.event.projection -import eventDemo.app.entity.Card -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player -import eventDemo.app.event.event.CardIsPlayedEvent -import eventDemo.app.event.event.GameStartedEvent -import eventDemo.app.event.event.NewPlayerEvent -import eventDemo.app.event.event.PlayerReadyEvent -import eventDemo.app.event.event.disableShuffleDeck +import eventDemo.business.entity.Card +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player +import eventDemo.business.event.event.CardIsPlayedEvent +import eventDemo.business.event.event.GameStartedEvent +import eventDemo.business.event.event.NewPlayerEvent +import eventDemo.business.event.event.PlayerReadyEvent +import eventDemo.business.event.event.disableShuffleDeck +import eventDemo.business.event.projection.GameState +import eventDemo.business.event.projection.apply import eventDemo.libs.event.VersionBuilderLocal import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.equals.shouldBeEqual diff --git a/src/test/kotlin/eventDemo/app/event/projection/GameStateRepositoryTest.kt b/src/test/kotlin/eventDemo/app/event/projection/GameStateRepositoryTest.kt index 4829bf5..533fe88 100644 --- a/src/test/kotlin/eventDemo/app/event/projection/GameStateRepositoryTest.kt +++ b/src/test/kotlin/eventDemo/app/event/projection/GameStateRepositoryTest.kt @@ -1,9 +1,10 @@ package eventDemo.app.event.projection -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player -import eventDemo.app.event.GameEventHandler -import eventDemo.app.event.event.NewPlayerEvent +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player +import eventDemo.business.event.GameEventHandler +import eventDemo.business.event.event.NewPlayerEvent +import eventDemo.business.event.projection.GameStateRepository import eventDemo.configuration.appKoinModule import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldHaveSize diff --git a/src/test/kotlin/eventDemo/app/event/projection/ProjectionSnapshotRepositoryInMemoryTest.kt b/src/test/kotlin/eventDemo/app/event/projection/ProjectionSnapshotRepositoryInMemoryTest.kt index 5d11717..ba80831 100644 --- a/src/test/kotlin/eventDemo/app/event/projection/ProjectionSnapshotRepositoryInMemoryTest.kt +++ b/src/test/kotlin/eventDemo/app/event/projection/ProjectionSnapshotRepositoryInMemoryTest.kt @@ -1,10 +1,13 @@ package eventDemo.app.event.projection +import eventDemo.business.event.projection.Projection import eventDemo.libs.event.AggregateId import eventDemo.libs.event.Event import eventDemo.libs.event.EventStore import eventDemo.libs.event.EventStoreInMemory import eventDemo.libs.event.VersionBuilderLocal +import eventDemo.libs.event.projection.ProjectionSnapshotRepositoryInMemory +import eventDemo.libs.event.projection.SnapshotConfig import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.equals.shouldBeEqual import kotlinx.coroutines.DelicateCoroutinesApi diff --git a/src/test/kotlin/eventDemo/app/query/GameStateRouteTest.kt b/src/test/kotlin/eventDemo/app/query/GameStateRouteTest.kt index 2619d3a..1ca6913 100644 --- a/src/test/kotlin/eventDemo/app/query/GameStateRouteTest.kt +++ b/src/test/kotlin/eventDemo/app/query/GameStateRouteTest.kt @@ -1,15 +1,15 @@ package eventDemo.app.query -import eventDemo.app.entity.Card -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player -import eventDemo.app.event.GameEventHandler -import eventDemo.app.event.event.CardIsPlayedEvent -import eventDemo.app.event.event.GameStartedEvent -import eventDemo.app.event.event.NewPlayerEvent -import eventDemo.app.event.event.PlayerReadyEvent -import eventDemo.app.event.projection.GameState -import eventDemo.app.event.projection.GameStateRepository +import eventDemo.business.entity.Card +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player +import eventDemo.business.event.GameEventHandler +import eventDemo.business.event.event.CardIsPlayedEvent +import eventDemo.business.event.event.GameStartedEvent +import eventDemo.business.event.event.NewPlayerEvent +import eventDemo.business.event.event.PlayerReadyEvent +import eventDemo.business.event.projection.GameState +import eventDemo.business.event.projection.GameStateRepository import eventDemo.configuration.configure import eventDemo.configuration.makeJwt import io.kotest.core.spec.style.FunSpec diff --git a/src/test/kotlin/eventDemo/app/query/GameStateTest.kt b/src/test/kotlin/eventDemo/app/query/GameStateTest.kt index 948a6e2..e6595b8 100644 --- a/src/test/kotlin/eventDemo/app/query/GameStateTest.kt +++ b/src/test/kotlin/eventDemo/app/query/GameStateTest.kt @@ -1,29 +1,29 @@ package eventDemo.app.query -import eventDemo.app.command.GameCommandHandler -import eventDemo.app.command.command.GameCommand -import eventDemo.app.command.command.IWantToJoinTheGameCommand -import eventDemo.app.command.command.IWantToPlayCardCommand -import eventDemo.app.command.command.IamReadyToPlayCommand -import eventDemo.app.entity.Card -import eventDemo.app.entity.GameId -import eventDemo.app.entity.Player -import eventDemo.app.event.GameEventStore -import eventDemo.app.event.event.disableShuffleDeck -import eventDemo.app.event.projection.GameState -import eventDemo.app.event.projection.ProjectionSnapshotRepositoryInMemory -import eventDemo.app.event.projection.apply -import eventDemo.app.eventListener.PlayerNotificationEventListener -import eventDemo.app.eventListener.ReactionEventListener -import eventDemo.app.notification.CommandSuccessNotification -import eventDemo.app.notification.ItsTheTurnOfNotification -import eventDemo.app.notification.Notification -import eventDemo.app.notification.PlayerAsJoinTheGameNotification -import eventDemo.app.notification.PlayerAsPlayACardNotification -import eventDemo.app.notification.PlayerWasReadyNotification -import eventDemo.app.notification.TheGameWasStartedNotification -import eventDemo.app.notification.WelcomeToTheGameNotification +import eventDemo.business.command.GameCommandHandler +import eventDemo.business.command.command.GameCommand +import eventDemo.business.command.command.IWantToJoinTheGameCommand +import eventDemo.business.command.command.IWantToPlayCardCommand +import eventDemo.business.command.command.IamReadyToPlayCommand +import eventDemo.business.entity.Card +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player +import eventDemo.business.event.GameEventStore +import eventDemo.business.event.event.disableShuffleDeck +import eventDemo.business.event.eventListener.PlayerNotificationEventListener +import eventDemo.business.event.eventListener.ReactionEventListener +import eventDemo.business.event.projection.GameState +import eventDemo.business.event.projection.apply +import eventDemo.business.notification.CommandSuccessNotification +import eventDemo.business.notification.ItsTheTurnOfNotification +import eventDemo.business.notification.Notification +import eventDemo.business.notification.PlayerAsJoinTheGameNotification +import eventDemo.business.notification.PlayerAsPlayACardNotification +import eventDemo.business.notification.PlayerWasReadyNotification +import eventDemo.business.notification.TheGameWasStartedNotification +import eventDemo.business.notification.WelcomeToTheGameNotification import eventDemo.configuration.appKoinModule +import eventDemo.libs.event.projection.ProjectionSnapshotRepositoryInMemory import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.equals.shouldBeEqual @@ -31,6 +31,7 @@ import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.trySendBlocking import kotlinx.coroutines.delay import kotlinx.coroutines.joinAll import kotlinx.coroutines.launch @@ -174,8 +175,8 @@ class GameStateTest : val eventStore by inject() val playerNotificationListener by inject() ReactionEventListener(get(), get(), get()).init() - playerNotificationListener.startListening(channelNotification1, player1) - playerNotificationListener.startListening(channelNotification2, player2) + playerNotificationListener.startListening({ channelNotification1.trySendBlocking(it) }, player1) + playerNotificationListener.startListening({ channelNotification2.trySendBlocking(it) }, player2) GlobalScope.launch(Dispatchers.IO) { commandHandler.handle(player1, channelCommand1, channelNotification1)