Last active
January 21, 2019 17:03
-
-
Save TylerPachal/915ee4d0ff82dbfcb7e0bb011208f13d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 {:ok, user} <- Users.get(user_id), | |
{:ok, game} <- Games.get(game_id), | |
false <- Game.is_full?(game), | |
false <- Game.is_started?(game), | |
true <- User.has_permission?(user, game) | |
do | |
Game.add_user(game, user) | |
else | |
:not_found -> {:error, "User or game not found"} | |
true -> {:error, "Game is full, or game has already started"} | |
false -> {:error, "User does not have permission"} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment