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 2b197d3105..258b52171c 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 @@ -24,7 +24,7 @@ import kotlinx.coroutines.coroutineScope import kotools.types.collection.NotEmptyList import kotools.types.collection.toNotEmptyList -interface ServerSpinCommandDispatcher : +interface ServerSpinCommandDispatcher : SpinCommand.Dispatcher, PartyIdPairAssignmentDocumentSaveSyntax, PartyIdLoadSyntax, @@ -32,7 +32,7 @@ interface ServerSpinCommandDispatcher : PartyIdLoadPlayersSyntax, PartyIdHistorySyntax, PartyIdPinRecordsSyntax, - CannonProvider where D : ShufflePairsAction.Dispatcher { + CannonProvider where 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 0af44c8853..1600ada755 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 @@ -10,6 +10,7 @@ import com.zegreatrob.coupling.model.pairassignmentdocument.PinnedCouplingPair 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.async.SimpleSuspendAction import kotools.types.collection.NotEmptyList @@ -19,11 +20,12 @@ data class ShufflePairsAction( val players: NotEmptyList, val pins: List, val history: List, -) : SimpleSuspendAction { - override val performFunc = link(Dispatcher::perform) +) : SimpleSuspendAction, PairAssignmentDocument> { + override val performFunc = link(Dispatcher<*>::perform) - interface Dispatcher : + interface Dispatcher : Clock, + CannonProvider, ExecutableActionExecuteSyntax, FindNewPairsAction.Dispatcher, AssignPinsActionDispatcher { 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 a9c9245e9c..2ea4ee336f 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 @@ -17,6 +17,7 @@ import com.zegreatrob.coupling.model.party.PartyDetails import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.model.player.Player import com.zegreatrob.minassert.assertIsEqualTo +import com.zegreatrob.testmints.action.ActionCannon import com.zegreatrob.testmints.setup import kotlinx.datetime.LocalDateTime import kotlinx.datetime.TimeZone @@ -28,7 +29,7 @@ import kotlin.test.Test class GameExamplesTest { companion object : - ShufflePairsAction.Dispatcher, + ShufflePairsAction.Dispatcher, FindNewPairsAction.Dispatcher, NextPlayerAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher, @@ -37,6 +38,7 @@ class GameExamplesTest { Wheel { override val wheel = this override val actionDispatcher = this + override val cannon = ActionCannon.invoke(this) override val execute = this } 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 f12821fdb9..a21396052e 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 @@ -16,6 +16,7 @@ import com.zegreatrob.coupling.stubmodel.stubPlayer import com.zegreatrob.minassert.assertIsEqualTo import com.zegreatrob.minspy.SpyData import com.zegreatrob.minspy.spyFunction +import com.zegreatrob.testmints.action.ActionCannon import com.zegreatrob.testmints.setup import kotlinx.datetime.Clock import kotools.types.collection.NotEmptyList @@ -26,7 +27,8 @@ class ShufflePairsActionTest { @Test fun willBuildAGameRunWithAllAvailablePlayersAndThenReturnTheResults() = setup(object : - ShufflePairsAction.Dispatcher { + ShufflePairsAction.Dispatcher { + override val cannon: ActionCannon get() = TODO("Not yet implemented") override val execute = stubActionExecutor(NextPlayerAction::class) override val wheel: Wheel get() = throw NotImplementedError("Stubbed") diff --git a/server/src/jsMain/kotlin/Handler.kt b/server/src/jsMain/kotlin/Handler.kt index 69f9465fae..50010afe87 100644 --- a/server/src/jsMain/kotlin/Handler.kt +++ b/server/src/jsMain/kotlin/Handler.kt @@ -102,7 +102,7 @@ fun serverlessSocketConnect(event: dynamic, context: dynamic) = js("require('ser private suspend fun handleConnect(request: Request, connectionId: String, event: Any?): Int { val commandDispatcher = with(request) { commandDispatcher(user, scope, traceId) } val partyId = request.query["partyId"].toString().let(::PartyId) - val result = commandDispatcher.execute(ConnectPartyUserCommand(partyId, connectionId)) + val result = commandDispatcher.perform(ConnectPartyUserCommand(partyId, connectionId)) return if (result == null) { 403 } else { @@ -148,7 +148,7 @@ fun serverlessSocketMessage(event: Json): dynamic { return MainScope().promise { val socketDispatcher = socketDispatcher() if (message is PairAssignmentAdjustmentMessage) { - socketDispatcher.execute( + socketDispatcher.perform( ReportDocCommand(connectionId, message.currentPairAssignments), )?.broadcast(socketDispatcher) } @@ -162,7 +162,7 @@ fun notifyConnect(event: Json) = MainScope().promise { val connectionId = event.at("/requestContext/connectionId") ?: "" println("notifyConnect $connectionId") val socketDispatcher = socketDispatcher() - socketDispatcher.execute(ConnectionsQuery(connectionId)) + socketDispatcher.perform(ConnectionsQuery(connectionId)) ?.let { results -> socketDispatcher.managementApiClient.send( PostToConnectionCommand( @@ -185,7 +185,7 @@ fun serverlessSocketDisconnect(event: dynamic) = MainScope().promise { val socketDispatcher = socketDispatcher() socketDispatcher - .execute(DisconnectPartyUserCommand(connectionId)) + .perform(DisconnectPartyUserCommand(connectionId)) ?.broadcast(socketDispatcher) .let { json("statusCode" to 200) } } @@ -197,7 +197,7 @@ private suspend fun CoroutineScope.socketDispatcher() = commandDispatcher( ) private suspend fun Pair, CouplingSocketMessage>.broadcast(socketDispatcher: CommandDispatcher) = - socketDispatcher.execute(BroadcastAction(first, second)) + socketDispatcher.perform(BroadcastAction(first, second)) private fun delete(connectionId: String, managementApi: ApiGatewayManagementApiClient) = managementApi.send( DeleteConnectionCommand(json("ConnectionId" to connectionId)), 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 159b01f706..3a12b8c2db 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/CommandDispatcher.kt @@ -28,6 +28,7 @@ import com.zegreatrob.coupling.server.action.pairassignmentdocument.PairAssignme import com.zegreatrob.coupling.server.action.pairassignmentdocument.ServerDeletePairAssignmentsCommandDispatcher import com.zegreatrob.coupling.server.action.pairassignmentdocument.ServerSavePairAssignmentDocumentCommandDispatcher import com.zegreatrob.coupling.server.action.pairassignmentdocument.ServerSpinCommandDispatcher +import com.zegreatrob.coupling.server.action.pairassignmentdocument.ShufflePairsAction import com.zegreatrob.coupling.server.action.party.PartyIntegrationQuery import com.zegreatrob.coupling.server.action.party.ServerDeletePartyCommandDispatcher import com.zegreatrob.coupling.server.action.pin.PinsQuery @@ -50,6 +51,7 @@ import com.zegreatrob.coupling.server.secret.JwtSecretGenerator import com.zegreatrob.coupling.server.secret.ServerDeleteSecretCommandDispatcher import com.zegreatrob.coupling.server.slack.FetchSlackRepository import com.zegreatrob.testmints.action.ActionCannon +import com.zegreatrob.testmints.action.ExecutableActionExecutor import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.async @@ -64,9 +66,7 @@ interface ICommandDispatcher : ConnectionsQuery.Dispatcher, CurrentPairAssignmentDocumentQuery.Dispatcher, DisconnectPartyUserCommand.Dispatcher, - DispatchingActionExecutor, GlobalStatsQuery.Dispatcher, - PairAssignmentDispatcher, PairAssignmentDocumentListQuery.Dispatcher, PartyDispatcher, PinsQuery.Dispatcher, @@ -88,9 +88,6 @@ class CommandDispatcher( override val traceId: Uuid, override val managementApiClient: ApiGatewayManagementApiClient = apiGatewayManagementApiClient(), ) : ICommandDispatcher, RepositoryCatalog by repositoryCatalog, TraceIdProvider { - override val execute = this - override val actionDispatcher = this - override val slackRepository: SlackRepository by lazy { FetchSlackRepository() } private var authorizedPartyIdDispatcherJob: Deferred? = null @@ -121,6 +118,9 @@ class CurrentPartyDispatcher( private val commandDispatcher: CommandDispatcher, ) : ICommandDispatcher by commandDispatcher, + DispatchingActionExecutor, + ShufflePairsAction.Dispatcher, + PairAssignmentDispatcher, ServerSpinCommandDispatcher, ServerSaveSlackIntegrationCommandDispatcher, ServerCreateSecretCommandDispatcher, @@ -135,11 +135,10 @@ class CurrentPartyDispatcher( ServerSavePinCommandDispatcher, CannonProvider { override val userId: String get() = commandDispatcher.userId - + override val execute: ExecutableActionExecutor> = this override val cannon: ActionCannon = ActionCannon(this, LoggingActionPipe(traceId)) - suspend fun isAuthorized() = currentPartyId.validateAuthorized() != null - + override val actionDispatcher = this private suspend fun PartyId.validateAuthorized() = if (userIsAuthorized(this)) this else null private suspend fun userIsAuthorized(partyId: PartyId) = currentUser.authorizedPartyIds.contains(partyId) || 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 ebbd2dde99..6973a74a01 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 @@ -8,13 +8,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 : - ShufflePairsAction.Dispatcher, +interface PairAssignmentDispatcher : + ShufflePairsAction.Dispatcher, FindNewPairsAction.Dispatcher, NextPlayerAction.Dispatcher, CreatePairCandidateReportListAction.Dispatcher, CreatePairCandidateReportAction.Dispatcher, Wheel { - override val execute: ExecutableActionExecutor + override val execute: ExecutableActionExecutor> override val wheel: Wheel get() = this }