gameActionHandler :: Handler b LokaService ()
gameActionHandler = do
  gameId <- getParam "gameId"
  maybe (writeBS $ jsonError "Invalid game ID") (\gameIdValid -> do
    gameState <- liftIO . getGameState $ ((read $ B.unpack gameIdValid) :: Integer)
    body <- readRequestBody 16384
    maybe (writeBS $ jsonError "Parse error") (\action -> do
      maybe (writeBS $ jsonError "Invalid game move") (\newGameState -> do
        liftIO $ addAction ((read $ B.unpack gameIdValid) :: Integer)
          (actor action)
          (Jsonify.move action)
        writeBS $ LB.toStrict $ encode $ JsonGameState (map
          (uncurry JsonAction)
          newGameState) $ collapseGameState gameState) $
            appendGameMove (actor action) (Jsonify.move action) gameState)
              $ decode body)
                gameId

------------------------------------------------------------------------------
-- | Handles and responds to a request to get all possible moves for a given
-- color.
gameActionHandler :: Handler b LokaService ()
gameActionHandler = do
  gameId <- getParam "gameId"
  maybe (writeBS $ jsonError "Invalid game ID") (\gameIdValid -> do
    gameState <- liftIO . getGameState $ ((read $ B.unpack gameIdValid) :: Integer)
    body <- readRequestBody 16384
    maybe (writeBS $ jsonError "Parse error") (\action -> do
      maybe (writeBS $ jsonError "Invalid game move") (\newGameState -> do
        liftIO $ addAction ((read $ B.unpack gameIdValid) :: Integer)
          (actor action)
          (Jsonify.move action)
        writeBS $ LB.toStrict $ encode $ JsonGameState (map
          (uncurry JsonAction)
          newGameState) $ collapseGameState gameState) $
            appendGameMove (actor action) (Jsonify.move action) gameState)
              $ decode body)
                gameId

------------------------------------------------------------------------------
-- | Handles and responds to a request to get all possible moves for a given
-- color.
gameActionHandler = do
  gameId <- getParam "gameId"
  maybe (writeBS $ jsonError "Invalid game ID") (\gameIdValid -> do
    gameState <- liftIO . getGameState $ ((read $ B.unpack gameIdValid) :: Integer)
    body <- readRequestBody 16384
    maybe (writeBS $ jsonError "Parse error") (\action -> do
      maybe (writeBS $ jsonError "Invalid game move") (\newGameState -> do
        liftIO $ addAction ((read $ B.unpack gameIdValid) :: Integer)
          (actor action)
          (Jsonify.move action)
        writeBS $ LB.toStrict $ encode $ JsonGameState (map
          (uncurry JsonAction)
          newGameState) $ collapseGameState gameState) $
            appendGameMove (actor action) (Jsonify.move action) gameState)
              $ decode body)
                gameId

------------------------------------------------------------------------------
-- | Handles and responds to a request to get all possible moves for a given
-- color.