Skip to content

Instantly share code, notes, and snippets.

@lasseebert
Created October 17, 2016 21:46
Show Gist options
  • Select an option

  • Save lasseebert/2fd06856af1a689a72a4600663d67fcd to your computer and use it in GitHub Desktop.

Select an option

Save lasseebert/2fd06856af1a689a72a4600663d67fcd to your computer and use it in GitHub Desktop.
defmodule MyApp.UserController do
use MyApp.Web, :controller
def create(conn, params) do
attrs = %{email: params["email"]}
case MyApp.Users.Invite.call(attrs) do
{:ok, user} ->
render_user(conn, user)
{:error, :invalid_email} ->
resp(conn, 400, %{message: "email is invalid"} |> Poison.encode!)
end
end
defp render_user(conn, user) do
{:ok, body} = %{
id: user.id,
email: user.email
}
|> Poison.encode
conn
|> resp(201, body)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment