From 06411cc442045ed0c7bc9a0dc26e3814a85183cb Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Tue, 17 Jan 2023 13:59:45 -0700 Subject: [PATCH] Merge default changeset on all status --- lib/chessh/ssh/client/game/game.ex | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/chessh/ssh/client/game/game.ex b/lib/chessh/ssh/client/game/game.ex index 386fcb3..2ee6dca 100644 --- a/lib/chessh/ssh/client/game/game.ex +++ b/lib/chessh/ssh/client/game/game.ex @@ -294,39 +294,41 @@ defmodule Chessh.SSH.Client.Game do attempted_move ) do {:ok, status} -> + {:ok, fen} = :binbo.get_fen(binbo_pid) + + default_changeset = %{ + fen: fen, + moves: game.moves + 1, + turn: if(game.turn == :dark, do: :light, else: :dark) + } + case status do :continue -> - {:ok, fen} = :binbo.get_fen(binbo_pid) - {:ok, _new_game} = Game.changeset( game, - %{ - fen: fen, - moves: game.moves + 1, - turn: if(game.turn == :dark, do: :light, else: :dark) - } + default_changeset ) |> Repo.update() {:draw, _} -> Game.changeset( game, - %{status: :draw} + Map.merge(default_changeset, %{status: :draw}) ) |> Repo.update() {:checkmate, :white_wins} -> Game.changeset( game, - %{status: :winner, winner: :light} + Map.merge(default_changeset, %{status: :winner, winner: :light}) ) |> Repo.update() {:checkmate, :black_wins} -> Game.changeset( game, - %{status: :winner, winner: :dark} + Map.merge(default_changeset, %{status: :winner, winner: :dark}) ) |> Repo.update() end