From 9790e96cd9e787af0283d51fabf127f73a9a0ade Mon Sep 17 00:00:00 2001 From: RoB Murdock Date: Tue, 18 Jul 2023 13:42:25 -0400 Subject: [PATCH] more cannon --- .../action/pairassignmentdocument/AssignPinsAction.kt | 4 ++-- .../pairassignmentdocument/ServerSpinCommandDispatcher.kt | 5 ++++- .../action/pairassignmentdocument/ShufflePairsAction.kt | 8 ++------ .../action/pairassignmentdocument/GameExamplesTest.kt | 4 +++- .../pairassignmentdocument/ShufflePairsActionTest.kt | 7 +++++-- .../com/zegreatrob/coupling/server/CommandDispatcher.kt | 2 ++ .../entity/pairassignment/PairAssignmentDispatcher.kt | 5 +++-- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/AssignPinsAction.kt b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/AssignPinsAction.kt index 38a079c840..eba8cda384 100644 --- a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/AssignPinsAction.kt +++ b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/AssignPinsAction.kt @@ -9,14 +9,14 @@ import com.zegreatrob.coupling.model.pairassignmentdocument.withPins import com.zegreatrob.coupling.model.pin.Pin import com.zegreatrob.coupling.model.pin.PinTarget import com.zegreatrob.coupling.model.player.Player -import com.zegreatrob.testmints.action.SimpleExecutableAction +import com.zegreatrob.testmints.action.async.SimpleSuspendAction import kotools.types.collection.NotEmptyList data class AssignPinsAction( val pairs: NotEmptyList, val pins: List, val history: List, -) : SimpleExecutableAction> { +) : SimpleSuspendAction> { override val performFunc = link(AssignPinsActionDispatcher::perform) } diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt index bb92f1ba3c..016d53ed17 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ServerSpinCommandDispatcher.kt @@ -1,6 +1,7 @@ package com.zegreatrob.coupling.server.action.pairassignmentdocument import com.zegreatrob.coupling.action.VoidResult +import com.zegreatrob.coupling.action.pairassignmentdocument.AssignPinsActionDispatcher import com.zegreatrob.coupling.action.pairassignmentdocument.SpinCommand import com.zegreatrob.coupling.model.elements import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocument @@ -32,7 +33,9 @@ interface ServerSpinCommandDispatcher : PartyIdLoadPlayersSyntax, PartyIdHistorySyntax, PartyIdPinRecordsSyntax, - CannonProvider where D : FindNewPairsAction.Dispatcher, D : ShufflePairsAction.Dispatcher { + CannonProvider where D : FindNewPairsAction.Dispatcher, + D : AssignPinsActionDispatcher, + D : ShufflePairsAction.Dispatcher { val slackRepository: SlackRepository val slackAccessRepository: SlackAccessGet diff --git a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt index d1efd4bf2d..7ac8de353c 100644 --- a/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt +++ b/server/action/src/commonMain/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsAction.kt @@ -11,7 +11,6 @@ import com.zegreatrob.coupling.model.party.PartyDetails import com.zegreatrob.coupling.model.pin.Pin import com.zegreatrob.coupling.model.player.Player import com.zegreatrob.coupling.server.action.CannonProvider -import com.zegreatrob.testmints.action.ExecutableActionExecuteSyntax import com.zegreatrob.testmints.action.annotation.ActionMint import kotools.types.collection.NotEmptyList @@ -24,14 +23,11 @@ data class ShufflePairsAction( ) { interface Dispatcher : Clock, - CannonProvider, - ExecutableActionExecuteSyntax, - AssignPinsActionDispatcher where D : FindNewPairsAction.Dispatcher { + CannonProvider where D : FindNewPairsAction.Dispatcher, D : AssignPinsActionDispatcher { suspend fun perform(action: ShufflePairsAction) = action.assignPinsToPairs().let(::pairAssignmentDocument) - private suspend fun ShufflePairsAction.assignPinsToPairs() = assignPins(findNewPairs()) - private fun ShufflePairsAction.assignPins(pairs: NotEmptyList) = execute(assignPinsAction(pairs)) + private suspend fun ShufflePairsAction.assignPinsToPairs() = cannon.fire(assignPinsAction(findNewPairs())) private suspend fun ShufflePairsAction.findNewPairs() = cannon.fire(findNewPairsAction()) private fun ShufflePairsAction.assignPinsAction(pairs: NotEmptyList) = diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt index 89cbc1d207..6b56015176 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/GameExamplesTest.kt @@ -2,6 +2,7 @@ package com.zegreatrob.coupling.server.action.pairassignmentdocument import com.benasher44.uuid.uuid4 import com.zegreatrob.coupling.action.DispatchingActionExecutor +import com.zegreatrob.coupling.action.pairassignmentdocument.AssignPinsActionDispatcher import com.zegreatrob.coupling.model.flatMap import com.zegreatrob.coupling.model.map import com.zegreatrob.coupling.model.pairassignmentdocument.CouplingPair @@ -29,8 +30,9 @@ import kotlin.test.Test class GameExamplesTest { companion object : - ShufflePairsAction.Dispatcher, + ShufflePairsAction.Dispatcher, FindNewPairsAction.Dispatcher, + AssignPinsActionDispatcher, NextPlayerAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher, CreatePairCandidateReportListAction.Dispatcher, diff --git a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt index 53e47da5cc..61bbd6f848 100644 --- a/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt +++ b/server/action/src/commonTest/kotlin/com/zegreatrob/coupling/server/action/pairassignmentdocument/ShufflePairsActionTest.kt @@ -1,5 +1,6 @@ package com.zegreatrob.coupling.server.action.pairassignmentdocument +import com.zegreatrob.coupling.action.pairassignmentdocument.AssignPinsActionDispatcher import com.zegreatrob.coupling.model.map import com.zegreatrob.coupling.model.pairassignmentdocument.CouplingPair import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocument @@ -25,10 +26,12 @@ import kotlin.test.Test class ShufflePairsActionTest { + interface ShufflePairsActionInner : FindNewPairsAction.Dispatcher, AssignPinsActionDispatcher + @Test fun willBuildAGameRunWithAllAvailablePlayersAndThenReturnTheResults() = asyncSetup(object : - ShufflePairsAction.Dispatcher, FindNewPairsAction.Dispatcher { - override val cannon: ActionCannon get() = ActionCannon.invoke(this) + ShufflePairsAction.Dispatcher, ShufflePairsActionInner { + override val cannon = ActionCannon(this) override val execute = stubActionExecutor(NextPlayerAction::class) override val wheel: Wheel get() = throw NotImplementedError("Stubbed") diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt index 3a12b8c2db..de0dcf420e 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt @@ -4,6 +4,7 @@ import com.benasher44.uuid.Uuid import com.zegreatrob.coupling.action.DispatchingActionExecutor import com.zegreatrob.coupling.action.LoggingActionPipe import com.zegreatrob.coupling.action.TraceIdProvider +import com.zegreatrob.coupling.action.pairassignmentdocument.AssignPinsActionDispatcher import com.zegreatrob.coupling.model.Message import com.zegreatrob.coupling.model.PartyRecord import com.zegreatrob.coupling.model.party.PartyId @@ -120,6 +121,7 @@ class CurrentPartyDispatcher( ICommandDispatcher by commandDispatcher, DispatchingActionExecutor, ShufflePairsAction.Dispatcher, + AssignPinsActionDispatcher, PairAssignmentDispatcher, ServerSpinCommandDispatcher, ServerSaveSlackIntegrationCommandDispatcher, diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt index ecffe7ba0b..6067c8209b 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/PairAssignmentDispatcher.kt @@ -1,5 +1,6 @@ package com.zegreatrob.coupling.server.entity.pairassignment +import com.zegreatrob.coupling.action.pairassignmentdocument.AssignPinsActionDispatcher import com.zegreatrob.coupling.server.action.pairassignmentdocument.CreatePairCandidateReportAction import com.zegreatrob.coupling.server.action.pairassignmentdocument.CreatePairCandidateReportListAction import com.zegreatrob.coupling.server.action.pairassignmentdocument.FindNewPairsAction @@ -8,13 +9,13 @@ import com.zegreatrob.coupling.server.action.pairassignmentdocument.ShufflePairs import com.zegreatrob.coupling.server.action.pairassignmentdocument.Wheel import com.zegreatrob.testmints.action.ExecutableActionExecutor -interface PairAssignmentDispatcher : +interface PairAssignmentDispatcher : ShufflePairsAction.Dispatcher, FindNewPairsAction.Dispatcher, NextPlayerAction.Dispatcher, CreatePairCandidateReportListAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher, - Wheel { + Wheel where D : AssignPinsActionDispatcher, D : FindNewPairsAction.Dispatcher { override val execute: ExecutableActionExecutor> override val wheel: Wheel get() = this }