From 375b0968c00b402459b16ff1b2a2ebfc3feb3e7b Mon Sep 17 00:00:00 2001 From: Johan Haleby Date: Fri, 22 Dec 2023 16:24:19 +0100 Subject: [PATCH] Temporary removing spring-hateoas and fixed some issues in example project --- .../web/cqrs/gameplay/GamePlayController.kt | 26 ++++++++----------- .../web/cqrs/gameplay/GameViewController.kt | 25 +++++++----------- .../{test => main}/resources/application.yaml | 0 .../rps/decidermodel/web/TestBootstrap.kt | 6 ++--- 4 files changed, 23 insertions(+), 34 deletions(-) rename example/domain/rps/decider-web/src/{test => main}/resources/application.yaml (100%) diff --git a/example/domain/rps/decider-web/src/main/kotlin/org/occurrent/example/domain/rps/decidermodel/web/cqrs/gameplay/GamePlayController.kt b/example/domain/rps/decider-web/src/main/kotlin/org/occurrent/example/domain/rps/decidermodel/web/cqrs/gameplay/GamePlayController.kt index c4e6614ff..d5074e057 100644 --- a/example/domain/rps/decider-web/src/main/kotlin/org/occurrent/example/domain/rps/decidermodel/web/cqrs/gameplay/GamePlayController.kt +++ b/example/domain/rps/decider-web/src/main/kotlin/org/occurrent/example/domain/rps/decidermodel/web/cqrs/gameplay/GamePlayController.kt @@ -20,14 +20,8 @@ package org.occurrent.example.domain.rps.decidermodel.web.cqrs.gameplay import org.occurrent.application.service.blocking.ApplicationService import org.occurrent.dsl.decider.execute import org.occurrent.example.domain.rps.decidermodel.* -import org.occurrent.example.domain.rps.decidermodel.HandGesture.ROCK import org.occurrent.example.domain.rps.decidermodel.web.common.loggerFor -import org.springframework.hateoas.EntityModel -import org.springframework.hateoas.IanaLinkRelations import org.springframework.hateoas.RepresentationModel -import org.springframework.hateoas.server.mvc.andAffordances -import org.springframework.hateoas.server.mvc.linkTo -import org.springframework.hateoas.server.mvc.withRel import org.springframework.http.ResponseEntity import org.springframework.stereotype.Controller import org.springframework.web.bind.annotation.* @@ -40,26 +34,28 @@ class GamePlayController(private val applicationService: ApplicationService() +// : ResponseEntity> { @PutMapping("{gameId}") - fun initializeNewGame(@PathVariable("gameId") gameId: GameId, @RequestParam playerId: PlayerId): ResponseEntity> { + fun initializeNewGame(@PathVariable("gameId") gameId: GameId, @RequestParam playerId: PlayerId) : ResponseEntity { log.info("Initializing new game (gameId=$gameId)") // val self = linkTo(methodOn(GameViewController::class.java).showGame(gameId) as Any).withSelfRel() // val selfWithAffordances = self.andAffordance(afford(methodOn(GamePlayController::class.java).playGame(gameId, playerId, ROCK))) - val self = linkTo { showGame(gameId) } withRel IanaLinkRelations.SELF - val selfWithAffordances = self andAffordances { - afford { playGame(gameId, playerId, ROCK) } - } - - val model = EntityModel.of(PlayGameRepresentationModel()) - .add(selfWithAffordances) +// val self = linkTo { showGame(gameId) } withRel IanaLinkRelations.SELF +// val selfWithAffordances = self andAffordances { +// afford { playGame(gameId, playerId, ROCK) } +// } +// +// val model = EntityModel.of(PlayGameRepresentationModel()) +// .add(selfWithAffordances) val cmd = InitiateNewGame(gameId, Timestamp.now(), playerId) applicationService.execute(gameId, cmd, rps) - return ResponseEntity.ok().header("Location", "/games/$gameId").body(model) + return ResponseEntity.noContent().header("Location", "/games/$gameId").build() +// return ResponseEntity.ok().header("Location", "/games/$gameId").body(model) } @PostMapping("{gameId}/play") diff --git a/example/domain/rps/decider-web/src/main/kotlin/org/occurrent/example/domain/rps/decidermodel/web/cqrs/gameplay/GameViewController.kt b/example/domain/rps/decider-web/src/main/kotlin/org/occurrent/example/domain/rps/decidermodel/web/cqrs/gameplay/GameViewController.kt index c7ede1be8..70fa97844 100644 --- a/example/domain/rps/decider-web/src/main/kotlin/org/occurrent/example/domain/rps/decidermodel/web/cqrs/gameplay/GameViewController.kt +++ b/example/domain/rps/decider-web/src/main/kotlin/org/occurrent/example/domain/rps/decidermodel/web/cqrs/gameplay/GameViewController.kt @@ -26,6 +26,7 @@ import org.occurrent.dsl.view.updateView import org.occurrent.dsl.view.view import org.occurrent.example.domain.rps.decidermodel.* import org.occurrent.example.domain.rps.decidermodel.web.common.loggerFor +import org.occurrent.example.domain.rps.decidermodel.web.cqrs.gameplay.GameStatus.* import org.springframework.data.annotation.Id import org.springframework.data.annotation.TypeAlias import org.springframework.data.mongodb.core.MongoOperations @@ -51,28 +52,20 @@ sealed interface GameReadModel { val status: GameStatus @TypeAlias("Initialized") - data class Initialized(override val gameId: GameId, val initializedBy: PlayerId) : GameReadModel { - override val status = GameStatus.Initialized - } + data class Initialized(override val gameId: GameId, val initializedBy: PlayerId, override val status: GameStatus) : GameReadModel @TypeAlias("Ongoing") - data class Ongoing(override val gameId: GameId, val firstMove: Move, val secondMove: Move? = null) : GameReadModel { - override val status = GameStatus.Ongoing - } + data class Ongoing(override val gameId: GameId, val firstMove: Move, val secondMove: Move? = null, override val status: GameStatus) : GameReadModel sealed interface Ended : GameReadModel { val firstMove: Move val secondMove: Move @TypeAlias("Tied") - data class Tied(override val gameId: GameId, override val firstMove: Move, override val secondMove: Move) : Ended { - override val status = GameStatus.Tied - } + data class Tied(override val gameId: GameId, override val firstMove: Move, override val secondMove: Move, override val status: GameStatus) : Ended @TypeAlias("Won") - data class Won(override val gameId: GameId, override val firstMove: Move, override val secondMove: Move, val winner: PlayerId) : Ended { - override val status = GameStatus.Won - } + data class Won(override val gameId: GameId, override val firstMove: Move, override val secondMove: Move, val winner: PlayerId, override val status: GameStatus) : Ended } } @@ -88,10 +81,10 @@ private val gameView = view( initialState = null, updateState = { game, e -> when (e) { - is NewGameInitiated -> GameReadModel.Initialized(e.gameId, e.playerId) + is NewGameInitiated -> GameReadModel.Initialized(e.gameId, e.playerId, Initialized) is GameStarted -> game is HandGestureShown -> when (game) { - is GameReadModel.Initialized -> GameReadModel.Ongoing(e.gameId, firstMove = Move(e.player, e.gesture)) + is GameReadModel.Initialized -> GameReadModel.Ongoing(e.gameId, firstMove = Move(e.player, e.gesture), status = Ongoing) is GameReadModel.Ongoing -> game.copy(secondMove = Move(e.player, e.gesture)) else -> game } @@ -99,12 +92,12 @@ private val gameView = view( is GameEnded -> game is GameTied -> { val ongoingGame = game as GameReadModel.Ongoing - GameReadModel.Ended.Tied(e.gameId, ongoingGame.firstMove, ongoingGame.secondMove!!) + GameReadModel.Ended.Tied(e.gameId, ongoingGame.firstMove, ongoingGame.secondMove!!, Tied) } is GameWon -> { val ongoingGame = game as GameReadModel.Ongoing - GameReadModel.Ended.Won(e.gameId, ongoingGame.firstMove, ongoingGame.secondMove!!, e.winner) + GameReadModel.Ended.Won(e.gameId, ongoingGame.firstMove, ongoingGame.secondMove!!, e.winner, Won) } } } diff --git a/example/domain/rps/decider-web/src/test/resources/application.yaml b/example/domain/rps/decider-web/src/main/resources/application.yaml similarity index 100% rename from example/domain/rps/decider-web/src/test/resources/application.yaml rename to example/domain/rps/decider-web/src/main/resources/application.yaml diff --git a/example/domain/rps/decider-web/src/test/kotlin/org/occurrent/example/domain/rps/decidermodel/web/TestBootstrap.kt b/example/domain/rps/decider-web/src/test/kotlin/org/occurrent/example/domain/rps/decidermodel/web/TestBootstrap.kt index 6061f1708..59b56881d 100644 --- a/example/domain/rps/decider-web/src/test/kotlin/org/occurrent/example/domain/rps/decidermodel/web/TestBootstrap.kt +++ b/example/domain/rps/decider-web/src/test/kotlin/org/occurrent/example/domain/rps/decidermodel/web/TestBootstrap.kt @@ -25,8 +25,6 @@ import org.springframework.boot.testcontainers.service.connection.ServiceConnect import org.springframework.boot.with import org.springframework.context.annotation.Bean import org.testcontainers.containers.MongoDBContainer -import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy -import org.testcontainers.containers.wait.strategy.WaitStrategy @TestConfiguration(proxyBeanMethods = false) @@ -36,7 +34,9 @@ class TestBootstrap { @Bean @ServiceConnection @RestartScope - fun mongoDbContainer(): MongoDBContainer = MongoDBContainer("mongo:4.2.8") + fun mongoDbContainer(): MongoDBContainer = MongoDBContainer("mongo:4.2.8").apply { + portBindings = listOf("27017:27017") + } } fun main(args: Array) {