Last active
October 3, 2019 19:08
-
-
Save TylerPachal/6434b70bf2311027d4a4b26c96722f51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def join_game(user_id, game_id) do | |
with {:user, {:ok, user}} <- {:user, Users.get(user_id)}, | |
{:game, {:ok, game}} <- {:game, Games.get(game_id)}, | |
{:full, false} <- {:full, Game.is_full?(game)}, | |
{:started, false} <- {:started, Game.is_started?(game)}, | |
{:allowed, true} <- {:allowed, User.has_permission?(user, game)} | |
do | |
Game.add_user(game, user) | |
else | |
{:user, :not_found} -> {:error, "User not found"} | |
{:game, :not_found} -> {:error, "Game not found"} | |
{:full, _} -> {:error, "Game is full"} | |
{:started, _} -> {:error, "Game has already started"} | |
{:allowed, _} -> {:error, "User is not allowed to join this game"} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment