Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Push Event schemas out to Deck #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion FsUno.Domain/CommandHandler.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module FsUno.Domain.CommandHandlers

open Deck
open Game

// This version use F# agents (MailboxProcessor) to keep
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions FsUno.Domain/Deck.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ type Card =
type Direction =
| ClockWise
| CounterClockWise

// Game events

type GameId = GameId of int

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 }
29 changes: 3 additions & 26 deletions FsUno.Domain/Game.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

open Deck

type GameId = GameId of int

// Commands

type Command =
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions FsUno.Persistence.EventStore/Serialization.fs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -197,7 +197,7 @@ let valueConverter (valueType: Type) =

let converters =
let valueConverters =
getValues typeof<Game.GameId>.Assembly
getValues typeof<GameId>.Assembly
|> Seq.map valueConverter
|> Seq.toList
[ unionConverter;optionConverter]
Expand Down