Skip to content

Commit

Permalink
more cannon
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 18, 2023
1 parent b5fe7de commit 9790e96
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CouplingPair>,
val pins: List<Pin>,
val history: List<PairAssignmentDocument>,
) : SimpleExecutableAction<AssignPinsActionDispatcher, NotEmptyList<PinnedCouplingPair>> {
) : SimpleSuspendAction<AssignPinsActionDispatcher, NotEmptyList<PinnedCouplingPair>> {
override val performFunc = link(AssignPinsActionDispatcher::perform)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,7 +33,9 @@ interface ServerSpinCommandDispatcher<out D> :
PartyIdLoadPlayersSyntax,
PartyIdHistorySyntax,
PartyIdPinRecordsSyntax,
CannonProvider<D> where D : FindNewPairsAction.Dispatcher, D : ShufflePairsAction.Dispatcher<D> {
CannonProvider<D> where D : FindNewPairsAction.Dispatcher,
D : AssignPinsActionDispatcher,
D : ShufflePairsAction.Dispatcher<D> {

val slackRepository: SlackRepository
val slackAccessRepository: SlackAccessGet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,14 +23,11 @@ data class ShufflePairsAction(
) {
interface Dispatcher<out D> :
Clock,
CannonProvider<D>,
ExecutableActionExecuteSyntax,
AssignPinsActionDispatcher where D : FindNewPairsAction.Dispatcher {
CannonProvider<D> 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<CouplingPair>) = 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<CouplingPair>) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -29,8 +30,9 @@ import kotlin.test.Test
class GameExamplesTest {

companion object :
ShufflePairsAction.Dispatcher<FindNewPairsAction.Dispatcher>,
ShufflePairsAction.Dispatcher<Companion>,
FindNewPairsAction.Dispatcher,
AssignPinsActionDispatcher,
NextPlayerAction.Dispatcher,
CreatePairCandidateReportAction.Dispatcher,
CreatePairCandidateReportListAction.Dispatcher,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,10 +26,12 @@ import kotlin.test.Test

class ShufflePairsActionTest {

interface ShufflePairsActionInner : FindNewPairsAction.Dispatcher, AssignPinsActionDispatcher

@Test
fun willBuildAGameRunWithAllAvailablePlayersAndThenReturnTheResults() = asyncSetup(object :
ShufflePairsAction.Dispatcher<FindNewPairsAction.Dispatcher>, FindNewPairsAction.Dispatcher {
override val cannon: ActionCannon<FindNewPairsAction.Dispatcher> get() = ActionCannon.invoke(this)
ShufflePairsAction.Dispatcher<ShufflePairsActionInner>, ShufflePairsActionInner {
override val cannon = ActionCannon(this)
override val execute = stubActionExecutor(NextPlayerAction::class)
override val wheel: Wheel get() = throw NotImplementedError("Stubbed")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,6 +121,7 @@ class CurrentPartyDispatcher(
ICommandDispatcher by commandDispatcher,
DispatchingActionExecutor<CurrentPartyDispatcher>,
ShufflePairsAction.Dispatcher<CurrentPartyDispatcher>,
AssignPinsActionDispatcher,
PairAssignmentDispatcher<CurrentPartyDispatcher>,
ServerSpinCommandDispatcher<CurrentPartyDispatcher>,
ServerSaveSlackIntegrationCommandDispatcher,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<D : FindNewPairsAction.Dispatcher> :
interface PairAssignmentDispatcher<D> :
ShufflePairsAction.Dispatcher<D>,
FindNewPairsAction.Dispatcher,
NextPlayerAction.Dispatcher,
CreatePairCandidateReportListAction.Dispatcher,
CreatePairCandidateReportAction.Dispatcher,
Wheel {
Wheel where D : AssignPinsActionDispatcher, D : FindNewPairsAction.Dispatcher {
override val execute: ExecutableActionExecutor<PairAssignmentDispatcher<D>>
override val wheel: Wheel get() = this
}

0 comments on commit 9790e96

Please sign in to comment.