From c48d1bcea0aedc4ef458325d98dd3e2f24f18a11 Mon Sep 17 00:00:00 2001 From: bartelink Date: Fri, 15 Aug 2014 11:06:05 +0100 Subject: [PATCH 1/3] Pushed Event records out to Deck --- FsUno.Domain/Deck.fs | 35 +++++++++++++++++++ FsUno.Domain/Game.fs | 29 ++------------- FsUno.Persistence.EventStore/Serialization.fs | 4 +-- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/FsUno.Domain/Deck.fs b/FsUno.Domain/Deck.fs index 4b1660c..30f60bb 100644 --- a/FsUno.Domain/Deck.fs +++ b/FsUno.Domain/Deck.fs @@ -25,3 +25,38 @@ type Card = type Direction = | ClockWise | CounterClockWise + +// Game events + +type GameId = GameId of int + +type GameStartedEvent = { + GameId: GameId + PlayerCount: int + FirstCard: Card + FirstPlayer: int } + +type CardPlayed = { + GameId: GameId + Player: int + Card: Card } + +type CardPlayedEvent = { + GameId: GameId + Player: int + Card: Card + NextPlayer: int } + +type PlayerPlayedAtWrongTurnEvent = { + GameId: GameId + Player: int + Card: Card } + +type PlayerPlayedWrongCardEvent = { + GameId: GameId + Player: int + Card: Card } + +type DirectionChangedEvent = { + GameId: GameId + Direction: Direction } \ No newline at end of file diff --git a/FsUno.Domain/Game.fs b/FsUno.Domain/Game.fs index 938f5bb..d0a357b 100644 --- a/FsUno.Domain/Game.fs +++ b/FsUno.Domain/Game.fs @@ -2,8 +2,6 @@ open Deck -type GameId = GameId of int - // Commands type Command = @@ -25,30 +23,9 @@ and PlayCard = { type Event = | GameStarted of GameStartedEvent | CardPlayed of CardPlayedEvent - | PlayerPlayedAtWrongTurn of PlayerPlayedWrong - | PlayerPlayedWrongCard of PlayerPlayedWrong - | DirectionChanged of DirectionChanged - -and GameStartedEvent = { - GameId: GameId - PlayerCount: int - FirstCard: Card - FirstPlayer: int } - -and CardPlayedEvent = { - GameId: GameId - Player: int - Card: Card - NextPlayer: int } - -and PlayerPlayedWrong = { - GameId: GameId - Player: int - Card: Card } - -and DirectionChanged = { - GameId: GameId - Direction: Direction } + | PlayerPlayedAtWrongTurn of PlayerPlayedAtWrongTurnEvent + | PlayerPlayedWrongCard of PlayerPlayedWrongCardEvent + | DirectionChanged of DirectionChangedEvent // Type representing current player turn; All operations should be encapsulated diff --git a/FsUno.Persistence.EventStore/Serialization.fs b/FsUno.Persistence.EventStore/Serialization.fs index 3ede70b..ca47a00 100644 --- a/FsUno.Persistence.EventStore/Serialization.fs +++ b/FsUno.Persistence.EventStore/Serialization.fs @@ -1,6 +1,6 @@ module Serialization -open FsUno.Domain +open FsUno.Domain.Deck // This module provides Json serialization to store // events in the event store @@ -197,7 +197,7 @@ let valueConverter (valueType: Type) = let converters = let valueConverters = - getValues typeof.Assembly + getValues typeof.Assembly |> Seq.map valueConverter |> Seq.toList [ unionConverter;optionConverter] From d4be060d6aeb1a3065052a2c367e2dc6f85f0c3d Mon Sep 17 00:00:00 2001 From: bartelink Date: Fri, 15 Aug 2014 13:05:59 +0100 Subject: [PATCH 2/3] Reformatted events to single line Removed stray junk --- FsUno.Domain/Deck.fs | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/FsUno.Domain/Deck.fs b/FsUno.Domain/Deck.fs index 30f60bb..199f089 100644 --- a/FsUno.Domain/Deck.fs +++ b/FsUno.Domain/Deck.fs @@ -30,33 +30,8 @@ type Direction = type GameId = GameId of int -type GameStartedEvent = { - GameId: GameId - PlayerCount: int - FirstCard: Card - FirstPlayer: int } - -type CardPlayed = { - GameId: GameId - Player: int - Card: Card } - -type CardPlayedEvent = { - GameId: GameId - Player: int - Card: Card - NextPlayer: int } - -type PlayerPlayedAtWrongTurnEvent = { - GameId: GameId - Player: int - Card: Card } - -type PlayerPlayedWrongCardEvent = { - GameId: GameId - Player: int - Card: Card } - -type DirectionChangedEvent = { - GameId: GameId - Direction: Direction } \ No newline at end of file +type GameStartedEvent = { GameId: GameId; PlayerCount: int; FirstCard: Card; FirstPlayer: int } +type CardPlayedEvent = { GameId: GameId; Player: int; Card: Card; NextPlayer: int } +type PlayerPlayedAtWrongTurnEvent = { GameId: GameId; Player: int; Card: Card } +type PlayerPlayedWrongCardEvent = { GameId: GameId; Player: int; Card: Card } +type DirectionChangedEvent = { GameId: GameId; Direction: Direction } \ No newline at end of file From 8537d2e7c6b1890422e91e0ebab6165f3185eb78 Mon Sep 17 00:00:00 2001 From: bartelink Date: Thu, 21 Aug 2014 23:12:34 +0100 Subject: [PATCH 3/3] Destructured GameId to resolve #6 --- FsUno.Domain/CommandHandler.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FsUno.Domain/CommandHandler.fs b/FsUno.Domain/CommandHandler.fs index 8eedc10..0028955 100644 --- a/FsUno.Domain/CommandHandler.fs +++ b/FsUno.Domain/CommandHandler.fs @@ -1,5 +1,6 @@ module FsUno.Domain.CommandHandlers +open Deck open Game // This version use F# agents (MailboxProcessor) to keep @@ -14,7 +15,7 @@ module Game = let create readStream appendToStream = // this is the "repository" - let streamId gameId = sprintf "Game-%O" gameId + let streamId (GameId gameId) = sprintf "Game-%O" gameId let load gameId = let rec fold state version = async {