debianize-mobilizon/lib/eventos_web/controllers/account_controller.ex
Thomas Citharel 1217361b6c fix some code style and add checks to ci
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2018-01-14 17:57:25 +01:00

42 lines
1.1 KiB
Elixir

defmodule EventosWeb.AccountController do
@moduledoc """
Controller for Accounts
"""
use EventosWeb, :controller
alias Eventos.Accounts
alias Eventos.Accounts.Account
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
accounts = Accounts.list_accounts()
render(conn, "index.json", accounts: accounts)
end
def show(conn, %{"id" => id}) do
account = Accounts.get_account_with_everything!(id)
render(conn, "show.json", account: account)
end
def update(conn, %{"id" => id, "account" => account_params}) do
account = Accounts.get_account!(id)
with {:ok, %Account{} = account} <- Accounts.update_account(account, account_params) do
render(conn, "show.json", account: account)
end
end
def delete(conn, %{"id" => id_str}) do
{id, _} = Integer.parse(id_str)
if Guardian.Plug.current_resource(conn).account.id == id do
account = Accounts.get_account!(id)
with {:ok, %Account{}} <- Accounts.delete_account(account) do
send_resp(conn, :no_content, "")
end
else
send_resp(conn, 401, "")
end
end
end