Skip to content

Instantly share code, notes, and snippets.

@inoas
Forked from TylerPachal/with_blogpost_6.ex
Created July 25, 2022 10:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save inoas/59b8dbbbbd16bf88852eae08a89ac9f1 to your computer and use it in GitHub Desktop.
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
# Don't care what specific thing failed
_ -> :error
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment