From f1d5f7ca84aceb9c0ad8f4df3ea2610a6f4c5563 Mon Sep 17 00:00:00 2001 From: RoB Murdock Date: Fri, 14 Jul 2023 00:01:45 -0400 Subject: [PATCH] switching a some commands used by the client app to the processor style --- .idea/compiler.xml | 19 +++++++ .idea/gradle.xml | 50 +++++++++++++++++++ .../client/components/DispatchFunc.kt | 7 +++ .../CurrentPairAssignmentsPanel.kt | 6 ++- .../pairassignments/PairAssignmentRow.kt | 7 ++- .../slack/SlackConnectPageContent.kt | 7 ++- .../client/components/spin/PrepareSpin.kt | 6 ++- .../client/components/StubDispatchFunc.kt | 16 ++++++ .../CurrentPairAssignmentsPanelTest.kt | 4 +- .../pairassignments/PairAssignmentRowTest.kt | 2 +- .../slack/SlackConnectPageContentTest.kt | 4 +- .../coupling/client/DecoratedDispatchFunc.kt | 15 ++++++ .../coupling/client/demo/DemoPageFrame.kt | 7 +++ .../SocketedPairAssignments.kt | 7 ++- coupling-plugins/gradle/libs.versions.toml | 2 +- gradle/libs.versions.toml | 2 +- .../DeletePairAssignmentsCommand.kt | 7 ++- .../SavePairAssignmentsCommand.kt | 7 ++- .../pairassignmentdocument/SpinCommand.kt | 8 ++- .../party/SaveSlackIntegrationCommand.kt | 8 ++- .../action/secret/CreateSecretCommand.kt | 8 ++- .../action/secret/DeleteSecretCommand.kt | 8 ++- .../pairassignment/DeletePairsResolver.kt | 12 +++-- .../entity/pairassignment/SavePairResolver.kt | 12 +++-- .../entity/pairassignment/SpinResolver.kt | 12 +++-- .../party/SaveSlackIntegrationResolver.kt | 8 +-- .../entity/secret/CreateSecretResolver.kt | 8 +-- .../entity/secret/DeleteSecretResolver.kt | 8 +-- settings.gradle.kts | 2 - 29 files changed, 201 insertions(+), 68 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 00c53664cb..d93132f55c 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -6,6 +6,12 @@ + + + + + + @@ -20,7 +26,20 @@ + + + + + + + + + + + + + diff --git a/.idea/gradle.xml b/.idea/gradle.xml index d21597f46d..a02a373e6e 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -7,11 +7,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -57,6 +88,25 @@ diff --git a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/DispatchFunc.kt b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/DispatchFunc.kt index 89628cf6dd..90ae127777 100644 --- a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/DispatchFunc.kt +++ b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/DispatchFunc.kt @@ -1,5 +1,6 @@ package com.zegreatrob.coupling.client.components +import com.zegreatrob.testmints.action.ActionCannon import com.zegreatrob.testmints.action.async.SuspendAction interface DispatchFunc { @@ -7,4 +8,10 @@ interface DispatchFunc { commandFunc: () -> C, response: (R) -> Unit, ): () -> Unit + + operator fun invoke( + commandFunc: () -> C, + fireCommand: suspend ActionCannon.(C) -> R, + response: (R) -> Unit, + ): () -> Unit } diff --git a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanel.kt b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanel.kt index 785dd2a59e..0653d00c2c 100644 --- a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanel.kt +++ b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanel.kt @@ -1,6 +1,7 @@ package com.zegreatrob.coupling.client.components.pairassignments import com.zegreatrob.coupling.action.pairassignmentdocument.DeletePairAssignmentsCommand +import com.zegreatrob.coupling.action.pairassignmentdocument.fire import com.zegreatrob.coupling.client.components.CouplingButton import com.zegreatrob.coupling.client.components.DispatchFunc import com.zegreatrob.coupling.client.components.Paths.currentPairsPage @@ -40,8 +41,9 @@ val CurrentPairAssignmentsPanel by nfc { props val (redirectUrl, setRedirectUrl) = useState(null) val redirectToCurrentFunc = { setRedirectUrl(party.id.currentPairsPage()) } val onCancel = dispatchFunc( - { DeletePairAssignmentsCommand(party.id, pairAssignments.id) }, - { redirectToCurrentFunc() }, + commandFunc = { DeletePairAssignmentsCommand(party.id, pairAssignments.id) }, + fireCommand = ::fire, + response = { redirectToCurrentFunc() }, ) if (redirectUrl != null) { Navigate { to = redirectUrl } diff --git a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRow.kt b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRow.kt index 3743141ce3..1d21e1e2d5 100644 --- a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRow.kt +++ b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRow.kt @@ -1,6 +1,7 @@ package com.zegreatrob.coupling.client.components.pairassignments import com.zegreatrob.coupling.action.pairassignmentdocument.DeletePairAssignmentsCommand +import com.zegreatrob.coupling.action.pairassignmentdocument.fire import com.zegreatrob.coupling.client.components.Controls import com.zegreatrob.coupling.client.components.CouplingButton import com.zegreatrob.coupling.client.components.external.w3c.WindowFunctions @@ -55,7 +56,11 @@ val PairAssignmentRow by nfc { props -> val windowFuncs = props.windowFunctions ?: WindowFunctions val (dispatchFunc, reload) = controls val onDeleteClick: () -> Unit = useCallback { - val deleteFunc = dispatchFunc({ DeletePairAssignmentsCommand(party.id, document.id) }, { reload() }) + val deleteFunc = dispatchFunc( + commandFunc = { DeletePairAssignmentsCommand(party.id, document.id) }, + fireCommand = ::fire, + response = { reload() }, + ) if (windowFuncs.window.confirm("Are you sure you want to delete these pair assignments?")) { deleteFunc.invoke() } diff --git a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContent.kt b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContent.kt index c5626fa8ae..cef395f3d7 100644 --- a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContent.kt +++ b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContent.kt @@ -3,6 +3,7 @@ package com.zegreatrob.coupling.client.components.slack import com.benasher44.uuid.uuid4 import com.zegreatrob.coupling.action.VoidResult import com.zegreatrob.coupling.action.party.SaveSlackIntegrationCommand +import com.zegreatrob.coupling.action.party.fire import com.zegreatrob.coupling.client.components.ConfigForm import com.zegreatrob.coupling.client.components.CouplingButton import com.zegreatrob.coupling.client.components.DispatchFunc @@ -49,7 +50,11 @@ val SlackConnectPageContent by nfc { props -> ) } var result by useState(null) - val onSave = props.dispatchFunc({ command }, { result = it }) + val onSave = props.dispatchFunc( + commandFunc = { command }, + fireCommand = ::fire, + response = { result = it }, + ) if (result == null) { ConfigForm { diff --git a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpin.kt b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpin.kt index d42c2db20f..3c83cd053d 100644 --- a/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpin.kt +++ b/client/components/src/jsMain/kotlin/com/zegreatrob/coupling/client/components/spin/PrepareSpin.kt @@ -1,6 +1,7 @@ package com.zegreatrob.coupling.client.components.spin import com.zegreatrob.coupling.action.pairassignmentdocument.SpinCommand +import com.zegreatrob.coupling.action.pairassignmentdocument.fire import com.zegreatrob.coupling.client.components.DispatchFunc import com.zegreatrob.coupling.client.components.Paths.newPairAssignmentsPath import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocument @@ -67,6 +68,7 @@ private fun onSpin( pinSelections: List, setRedirectUrl: (String) -> Unit, ) = dispatchFunc( - { SpinCommand(party.id, playerSelections.playerIds(), pinSelections.filterNotNull()) }, - { setRedirectUrl(party.newPairAssignmentsPath()) }, + commandFunc = { SpinCommand(party.id, playerSelections.playerIds(), pinSelections.filterNotNull()) }, + fireCommand = ::fire, + response = { setRedirectUrl(party.newPairAssignmentsPath()) }, ) diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/StubDispatchFunc.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/StubDispatchFunc.kt index d52c240207..f25732b1db 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/StubDispatchFunc.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/StubDispatchFunc.kt @@ -1,5 +1,7 @@ package com.zegreatrob.coupling.client.components +import com.zegreatrob.testmints.action.ActionCannon +import com.zegreatrob.testmints.action.ActionWrapper import com.zegreatrob.testmints.action.async.SuspendAction class StubDispatcher { @@ -13,6 +15,12 @@ class StubDispatcher { ?.responseFunc ?.invoke(result) } + fun wrappedSendResult(result: R) { + dispatchList.filterIsInstance, R>>() + .firstOrNull() + ?.responseFunc + ?.invoke(result) + } fun commandFunctionsDispatched() where C : SuspendAction = dispatchList.filterIsInstance>() @@ -34,4 +42,12 @@ class StubDispatchFunc(private val stubber: StubDispatcher = StubDispatcher() ): () -> Unit = { stubber.dispatchList.add(DispatchedFunc(commandFunc(), response)) } + + override fun invoke( + commandFunc: () -> C, + fireCommand: suspend ActionCannon.(C) -> R, + response: (R) -> Unit, + ): () -> Unit = { + stubber.dispatchList.add(DispatchedFunc(commandFunc(), response)) + } } diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanelTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanelTest.kt index e566b43ead..4261a82a72 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanelTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanelTest.kt @@ -62,7 +62,7 @@ class CurrentPairAssignmentsPanelTest { ) } exercise { actor.click(screen.getByText("Save!")) - stubDispatcher.sendResult(VoidResult.Accepted) + stubDispatcher.wrappedSendResult(VoidResult.Accepted) } verify { waitFor { stubDispatcher.commandsDispatched().size @@ -104,7 +104,7 @@ class CurrentPairAssignmentsPanelTest { ) } exercise { actor.click(screen.findByText("Cancel")) - act { stubDispatcher.sendResult(VoidResult.Accepted) } + act { stubDispatcher.wrappedSendResult(VoidResult.Accepted) } } verify { waitFor { stubDispatcher.commandsDispatched() diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRowTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRowTest.kt index 78a5bb534c..bfd19a2a46 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRowTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRowTest.kt @@ -45,7 +45,7 @@ class PairAssignmentRowTest { ) } exercise { actor.click(screen.getByText("DELETE")) - stubDispatcher.sendResult(VoidResult.Accepted) + stubDispatcher.wrappedSendResult(VoidResult.Accepted) } verify { stubDispatcher.commandsDispatched() .assertIsEqualTo(listOf(DeletePairAssignmentsCommand(party.id, document.id))) diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt index 4e305bb042..a540cc5b8b 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt @@ -52,7 +52,7 @@ class SlackConnectPageContentTest { .assertIsEqualTo(null, "Return button showed up unexpectedly early") } exercise { actor.click(saveButton) - act { stubber.sendResult(VoidResult.Accepted) } + act { stubber.wrappedSendResult(VoidResult.Accepted) } } verify { stubber.commandsDispatched() .assertIsEqualTo( @@ -113,7 +113,7 @@ class SlackConnectPageContentTest { }, ) actor.click(saveButton) - act { stubDispatcher.sendResult(VoidResult.Accepted) } + act { stubDispatcher.wrappedSendResult(VoidResult.Accepted) } } exercise { actor.click(returnButton) } verify { diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/DecoratedDispatchFunc.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/DecoratedDispatchFunc.kt index 597e90f5bb..c69f7d56a9 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/DecoratedDispatchFunc.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/DecoratedDispatchFunc.kt @@ -2,6 +2,7 @@ package com.zegreatrob.coupling.client import com.zegreatrob.coupling.client.components.DispatchFunc import com.zegreatrob.react.dataloader.DataLoaderTools +import com.zegreatrob.testmints.action.ActionCannon import com.zegreatrob.testmints.action.async.SuspendAction import com.zegreatrob.testmints.action.async.SuspendActionExecuteSyntax @@ -11,6 +12,7 @@ class DecoratedDispatchFunc( ) : DispatchFunc { private val dispatcher get() = dispatcherFunc() + private val cannon by lazy { ActionCannon(dispatcher) } override fun , R> invoke(commandFunc: () -> C, response: (R) -> Unit) = fun() { val command = commandFunc() @@ -20,4 +22,17 @@ class DecoratedDispatchFunc( response, ) } + + override fun invoke( + commandFunc: () -> C, + fireCommand: suspend ActionCannon.(C) -> R, + response: (R) -> Unit, + ): () -> Unit = fun() { + val command = commandFunc() + tools.performAsyncWork( + { fireCommand(cannon, command) }, + { handler: Throwable -> throw handler }, + response, + ) + } } diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/demo/DemoPageFrame.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/demo/DemoPageFrame.kt index 5ca94ff7f7..de8fb43f40 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/demo/DemoPageFrame.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/demo/DemoPageFrame.kt @@ -15,6 +15,7 @@ import com.zegreatrob.coupling.model.CouplingSocketMessage import com.zegreatrob.coupling.model.pin.Pin import com.zegreatrob.minreact.ReactFunc import com.zegreatrob.minreact.nfc +import com.zegreatrob.testmints.action.ActionCannon import com.zegreatrob.testmints.action.async.SuspendAction import emotion.react.css import js.core.jso @@ -135,6 +136,12 @@ class NoOpDispatcherDispatchFunc : DispatchFunc { commandFunc: () -> C, response: (R) -> Unit, ): () -> Unit = {} + + override fun invoke( + commandFunc: () -> C, + fireCommand: suspend ActionCannon.(C) -> R, + response: (R) -> Unit, + ) = {} } interface NoOpDispatcher : diff --git a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/SocketedPairAssignments.kt b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/SocketedPairAssignments.kt index c3bf51ac15..45a83dfdf7 100644 --- a/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/SocketedPairAssignments.kt +++ b/client/src/jsMain/kotlin/com/zegreatrob/coupling/client/pairassignments/SocketedPairAssignments.kt @@ -2,6 +2,7 @@ package com.zegreatrob.coupling.client.pairassignments import com.zegreatrob.coupling.action.pairassignmentdocument.DeletePairAssignmentsCommand import com.zegreatrob.coupling.action.pairassignmentdocument.SavePairAssignmentsCommand +import com.zegreatrob.coupling.action.pairassignmentdocument.fire import com.zegreatrob.coupling.client.components.Controls import com.zegreatrob.coupling.client.components.CouplingWebsocket import com.zegreatrob.coupling.client.components.disconnectedMessage @@ -41,7 +42,11 @@ val SocketedPairAssignments by nfc> { (party, pl val onMessageFunc: (Message) -> Unit = useCallback { handleMessage(it, setMessage, setPairAssignments) } val updatePairAssignments = useCallback(party.id, controls.dispatchFunc) { new: PairAssignmentDocument -> setPairAssignments(new) - controls.dispatchFunc({ SavePairAssignmentsCommand(party.id, new) }, {}).invoke() + controls.dispatchFunc( + commandFunc = { SavePairAssignmentsCommand(party.id, new) }, + fireCommand = ::fire, + response = {}, + ).invoke() } val auth0Data = useAuth0Data() var token by useState("") diff --git a/coupling-plugins/gradle/libs.versions.toml b/coupling-plugins/gradle/libs.versions.toml index 58f9abda9b..50a63e0e80 100644 --- a/coupling-plugins/gradle/libs.versions.toml +++ b/coupling-plugins/gradle/libs.versions.toml @@ -9,7 +9,7 @@ com-fasterxml-jackson-core-jackson-databind = "com.fasterxml.jackson.core:jackso com-github-ben-manes-gradle-versions-plugin = "com.github.ben-manes:gradle-versions-plugin:0.47.0" com-soywiz-korlibs-klock = "com.soywiz.korlibs.klock:klock:4.0.8" com-zegreatrob-jsmints-jsmints-bom = "com.zegreatrob.jsmints:jsmints-bom:4.3.13" -com-zegreatrob-testmints-testmints-bom = "com.zegreatrob.testmints:testmints-bom:10.0.19" +com-zegreatrob-testmints-testmints-bom = "com.zegreatrob.testmints:testmints-bom:10.0.20" com-zegreatrob-tools-tools-bom = "com.zegreatrob.tools:tools-bom:0.5.4" org-ajoberstar-grgit-gradle-plugin = "org.ajoberstar.grgit:org.ajoberstar.grgit.gradle.plugin:5.0.0" org-apache-logging-log4j-log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "org-apache-logging-log4j" } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3bb2567c60..ca01e61fd5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ com-fasterxml-jackson-core-jackson-databind = "com.fasterxml.jackson.core:jackso com-github-ajalt-clikt-clikt = "com.github.ajalt.clikt:clikt:4.0.0" com-soywiz-korlibs-klock = "com.soywiz.korlibs.klock:klock:4.0.8" com-zegreatrob-jsmints-jsmints-bom = "com.zegreatrob.jsmints:jsmints-bom:4.3.13" -com-zegreatrob-testmints-testmints-bom = "com.zegreatrob.testmints:testmints-bom:10.0.19" +com-zegreatrob-testmints-testmints-bom = "com.zegreatrob.testmints:testmints-bom:10.0.20" io-github-microutils-kotlin-logging = "io.github.microutils:kotlin-logging:3.0.5" io-ktor-ktor-bom = "io.ktor:ktor-bom:2.3.2" org-jetbrains-kotlin-wrappers-kotlin-wrappers-bom = "org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:1.0.0-pre.596" diff --git a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/DeletePairAssignmentsCommand.kt b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/DeletePairAssignmentsCommand.kt index 270d41482a..5120550330 100644 --- a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/DeletePairAssignmentsCommand.kt +++ b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/DeletePairAssignmentsCommand.kt @@ -3,14 +3,13 @@ package com.zegreatrob.coupling.action.pairassignmentdocument import com.zegreatrob.coupling.action.VoidResult import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocumentId import com.zegreatrob.coupling.model.party.PartyId -import com.zegreatrob.testmints.action.async.SimpleSuspendAction +import com.zegreatrob.testmints.action.annotation.MintAction +@MintAction data class DeletePairAssignmentsCommand( val partyId: PartyId, val pairAssignmentDocumentId: PairAssignmentDocumentId, -) : SimpleSuspendAction { - - override val performFunc = link(Dispatcher::perform) +) { @Suppress("FUN_INTERFACE_WITH_SUSPEND_FUNCTION") fun interface Dispatcher { diff --git a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/SavePairAssignmentsCommand.kt b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/SavePairAssignmentsCommand.kt index 4b4c35861a..ea2fd5d924 100644 --- a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/SavePairAssignmentsCommand.kt +++ b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/SavePairAssignmentsCommand.kt @@ -3,14 +3,13 @@ package com.zegreatrob.coupling.action.pairassignmentdocument import com.zegreatrob.coupling.action.VoidResult import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocument import com.zegreatrob.coupling.model.party.PartyId -import com.zegreatrob.testmints.action.async.SimpleSuspendAction +import com.zegreatrob.testmints.action.annotation.MintAction +@MintAction data class SavePairAssignmentsCommand( val partyId: PartyId, val pairAssignments: PairAssignmentDocument, -) : SimpleSuspendAction { - override val performFunc = link(Dispatcher::perform) - +) { interface Dispatcher { suspend fun perform(command: SavePairAssignmentsCommand): VoidResult } diff --git a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/SpinCommand.kt b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/SpinCommand.kt index c725905ca4..77f6136429 100644 --- a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/SpinCommand.kt +++ b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/pairassignmentdocument/SpinCommand.kt @@ -2,12 +2,10 @@ package com.zegreatrob.coupling.action.pairassignmentdocument import com.zegreatrob.coupling.action.VoidResult import com.zegreatrob.coupling.model.party.PartyId -import com.zegreatrob.testmints.action.async.SimpleSuspendAction - -data class SpinCommand(val partyId: PartyId, val playerIds: List, val pinIds: List) : - SimpleSuspendAction { - override val performFunc = link(Dispatcher::perform) +import com.zegreatrob.testmints.action.annotation.MintAction +@MintAction +data class SpinCommand(val partyId: PartyId, val playerIds: List, val pinIds: List) { interface Dispatcher { suspend fun perform(command: SpinCommand): VoidResult } diff --git a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/party/SaveSlackIntegrationCommand.kt b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/party/SaveSlackIntegrationCommand.kt index f76539c40c..2246fe6433 100644 --- a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/party/SaveSlackIntegrationCommand.kt +++ b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/party/SaveSlackIntegrationCommand.kt @@ -2,16 +2,14 @@ package com.zegreatrob.coupling.action.party import com.zegreatrob.coupling.action.VoidResult import com.zegreatrob.coupling.model.party.PartyId -import com.zegreatrob.testmints.action.async.SimpleSuspendAction +import com.zegreatrob.testmints.action.annotation.MintAction +@MintAction data class SaveSlackIntegrationCommand( val partyId: PartyId, val channel: String, val team: String, -) : - SimpleSuspendAction { - override val performFunc = link(Dispatcher::perform) - +) { interface Dispatcher { suspend fun perform(command: SaveSlackIntegrationCommand): VoidResult } diff --git a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/secret/CreateSecretCommand.kt b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/secret/CreateSecretCommand.kt index 3a4f26bb63..8e15b429a4 100644 --- a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/secret/CreateSecretCommand.kt +++ b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/secret/CreateSecretCommand.kt @@ -2,12 +2,10 @@ package com.zegreatrob.coupling.action.secret import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.model.party.Secret -import com.zegreatrob.testmints.action.async.SimpleSuspendAction - -data class CreateSecretCommand(val partyId: PartyId) : - SimpleSuspendAction?> { - override val performFunc = link(Dispatcher::perform) +import com.zegreatrob.testmints.action.annotation.MintAction +@MintAction +data class CreateSecretCommand(val partyId: PartyId) { interface Dispatcher { suspend fun perform(command: CreateSecretCommand): Pair? } diff --git a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/secret/DeleteSecretCommand.kt b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/secret/DeleteSecretCommand.kt index 540c68915f..43673f7fee 100644 --- a/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/secret/DeleteSecretCommand.kt +++ b/libraries/action/src/commonMain/kotlin/com/zegreatrob/coupling/action/secret/DeleteSecretCommand.kt @@ -3,12 +3,10 @@ package com.zegreatrob.coupling.action.secret import com.zegreatrob.coupling.action.VoidResult import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.model.party.Secret -import com.zegreatrob.testmints.action.async.SimpleSuspendAction - -data class DeleteSecretCommand(val partyId: PartyId, val secret: Secret) : - SimpleSuspendAction { - override val performFunc = link(Dispatcher::perform) +import com.zegreatrob.testmints.action.annotation.MintAction +@MintAction +data class DeleteSecretCommand(val partyId: PartyId, val secret: Secret) { interface Dispatcher { suspend fun perform(command: DeleteSecretCommand): VoidResult } diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/DeletePairsResolver.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/DeletePairsResolver.kt index 7fe0dcfd8d..07e53c69cf 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/DeletePairsResolver.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/DeletePairsResolver.kt @@ -1,16 +1,18 @@ package com.zegreatrob.coupling.server.entity.pairassignment import com.zegreatrob.coupling.action.pairassignmentdocument.DeletePairAssignmentsCommand +import com.zegreatrob.coupling.action.pairassignmentdocument.fire import com.zegreatrob.coupling.json.DeletePairAssignmentsInput import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocumentId import com.zegreatrob.coupling.server.graphql.DispatcherProviders.authorizedPartyDispatcher -import com.zegreatrob.coupling.server.graphql.dispatch +import com.zegreatrob.coupling.server.graphql.dispatchAction import kotlinx.serialization.json.JsonNull -val deletePairsResolver = dispatch( - { request, _: JsonNull, args -> authorizedPartyDispatcher(request, args.partyId.value) }, - { _, entity: DeletePairAssignmentsInput -> entity.toModel() }, - { true }, +val deletePairsResolver = dispatchAction( + dispatcherFunc = { request, _: JsonNull, args -> authorizedPartyDispatcher(request, args.partyId.value) }, + commandFunc = { _, entity: DeletePairAssignmentsInput -> entity.toModel() }, + fireCommand = ::fire, + toSerializable = { true }, ) private fun DeletePairAssignmentsInput.toModel() = DeletePairAssignmentsCommand( diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/SavePairResolver.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/SavePairResolver.kt index c1ec4795f5..66a0e5e88c 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/SavePairResolver.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/SavePairResolver.kt @@ -1,21 +1,23 @@ package com.zegreatrob.coupling.server.entity.pairassignment import com.zegreatrob.coupling.action.pairassignmentdocument.SavePairAssignmentsCommand +import com.zegreatrob.coupling.action.pairassignmentdocument.fire import com.zegreatrob.coupling.json.SavePairAssignmentsInput import com.zegreatrob.coupling.json.toModel import com.zegreatrob.coupling.server.graphql.DispatcherProviders.authorizedPartyDispatcher -import com.zegreatrob.coupling.server.graphql.dispatch +import com.zegreatrob.coupling.server.graphql.dispatchAction import kotlinx.serialization.json.JsonNull -val savePairsResolver = dispatch( - { request, _: JsonNull, args -> +val savePairsResolver = dispatchAction( + dispatcherFunc = { request, _: JsonNull, args -> authorizedPartyDispatcher( context = request, partyId = args.partyId.value, ) }, - { _, input: SavePairAssignmentsInput -> input.command() }, - { true }, + commandFunc = { _, input: SavePairAssignmentsInput -> input.command() }, + fireCommand = ::fire, + toSerializable = { true }, ) private fun SavePairAssignmentsInput.command() = SavePairAssignmentsCommand(partyId, toModel()) diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/SpinResolver.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/SpinResolver.kt index ca4f6a65a3..b42fcfa439 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/SpinResolver.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/pairassignment/SpinResolver.kt @@ -1,21 +1,23 @@ package com.zegreatrob.coupling.server.entity.pairassignment import com.zegreatrob.coupling.action.pairassignmentdocument.SpinCommand +import com.zegreatrob.coupling.action.pairassignmentdocument.fire import com.zegreatrob.coupling.json.SpinInput import com.zegreatrob.coupling.server.external.graphql.Resolver import com.zegreatrob.coupling.server.graphql.DispatcherProviders.authorizedPartyDispatcher -import com.zegreatrob.coupling.server.graphql.dispatch +import com.zegreatrob.coupling.server.graphql.dispatchAction import kotlinx.serialization.json.JsonNull -val spinResolver: Resolver = dispatch( - { request, _: JsonNull, args -> +val spinResolver: Resolver = dispatchAction( + dispatcherFunc = { request, _: JsonNull, args -> authorizedPartyDispatcher( context = request, partyId = args.partyId.value, ) }, - { _, args: SpinInput -> args.command() }, - { true }, + commandFunc = { _, args: SpinInput -> args.command() }, + fireCommand = ::fire, + toSerializable = { true }, ) private fun SpinInput.command() = SpinCommand( diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/party/SaveSlackIntegrationResolver.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/party/SaveSlackIntegrationResolver.kt index fe8110d13d..480159f9af 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/party/SaveSlackIntegrationResolver.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/party/SaveSlackIntegrationResolver.kt @@ -2,16 +2,18 @@ package com.zegreatrob.coupling.server.entity.party import com.zegreatrob.coupling.action.VoidResult import com.zegreatrob.coupling.action.party.SaveSlackIntegrationCommand +import com.zegreatrob.coupling.action.party.fire import com.zegreatrob.coupling.json.SaveSlackIntegrationInput import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.server.entity.toJson import com.zegreatrob.coupling.server.graphql.DispatcherProviders.authorizedPartyDispatcher -import com.zegreatrob.coupling.server.graphql.dispatch +import com.zegreatrob.coupling.server.graphql.dispatchAction import kotlinx.serialization.json.JsonNull -val saveSlackIntegrationResolver = dispatch( +val saveSlackIntegrationResolver = dispatchAction( dispatcherFunc = { request, _: JsonNull, args -> authorizedPartyDispatcher(request, args.partyId) }, - queryFunc = { _, input: SaveSlackIntegrationInput -> input.toCommand() }, + commandFunc = { _, input: SaveSlackIntegrationInput -> input.toCommand() }, + fireCommand = ::fire, toSerializable = VoidResult::toJson, ) diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/secret/CreateSecretResolver.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/secret/CreateSecretResolver.kt index 7e4b29a5aa..b9a0d0e5ea 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/secret/CreateSecretResolver.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/secret/CreateSecretResolver.kt @@ -1,16 +1,18 @@ package com.zegreatrob.coupling.server.entity.secret import com.zegreatrob.coupling.action.secret.CreateSecretCommand +import com.zegreatrob.coupling.action.secret.fire import com.zegreatrob.coupling.json.CreateSecretInput import com.zegreatrob.coupling.json.toModel import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.server.graphql.DispatcherProviders.authorizedPartyDispatcher -import com.zegreatrob.coupling.server.graphql.dispatch +import com.zegreatrob.coupling.server.graphql.dispatchAction import kotlinx.serialization.json.JsonNull -val createSecretResolver = dispatch( +val createSecretResolver = dispatchAction( dispatcherFunc = { request, _: JsonNull, args -> authorizedPartyDispatcher(request, args.partyId) }, - queryFunc = { _, input: CreateSecretInput -> input.toCommand() }, + commandFunc = { _, input: CreateSecretInput -> input.toCommand() }, + fireCommand = ::fire, toSerializable = { it?.toModel() }, ) diff --git a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/secret/DeleteSecretResolver.kt b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/secret/DeleteSecretResolver.kt index 79d8632c74..86f11643f7 100644 --- a/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/secret/DeleteSecretResolver.kt +++ b/server/src/jsMain/kotlin/com/zegreatrob/coupling/server/entity/secret/DeleteSecretResolver.kt @@ -1,20 +1,22 @@ package com.zegreatrob.coupling.server.entity.secret import com.zegreatrob.coupling.action.secret.DeleteSecretCommand +import com.zegreatrob.coupling.action.secret.fire import com.zegreatrob.coupling.json.DeleteSecretInput import com.zegreatrob.coupling.model.party.PartyId import com.zegreatrob.coupling.model.party.Secret import com.zegreatrob.coupling.server.graphql.DispatcherProviders -import com.zegreatrob.coupling.server.graphql.dispatch +import com.zegreatrob.coupling.server.graphql.dispatchAction import kotlinx.serialization.json.JsonNull -val deleteSecretResolver = dispatch( +val deleteSecretResolver = dispatchAction( dispatcherFunc = { request, _: JsonNull, args -> DispatcherProviders.authorizedPartyDispatcher( context = request, partyId = args.partyId, ) }, - queryFunc = { _, args: DeleteSecretInput -> DeleteSecretCommand(PartyId(args.partyId), Secret(args.secretId)) }, + commandFunc = { _, args: DeleteSecretInput -> DeleteSecretCommand(PartyId(args.partyId), Secret(args.secretId)) }, + fireCommand = ::fire, toSerializable = { true }, ) diff --git a/settings.gradle.kts b/settings.gradle.kts index 98cd98e7b2..fd451ce27a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -12,8 +12,6 @@ plugins { rootProject.name = "Coupling" includeBuild("coupling-plugins") -includeBuild("../testmints/libraries") { name = "testmints-libraries" } -includeBuild("../testmints/plugins") { name = "testmints-plugins" } include("cli") include("client")