mobilizon/lib/eventos_web/controllers/group_controller.ex
Thomas Citharel 90ceb4f6fe initial commit
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2017-12-08 09:58:14 +01:00

61 lines
1.7 KiB
Elixir

defmodule EventosWeb.GroupController do
use EventosWeb, :controller
alias Eventos.Accounts
alias Eventos.Accounts.Group
def index(conn, _params) do
groups = Accounts.list_groups()
render(conn, "index.html", groups: groups)
end
def new(conn, _params) do
changeset = Accounts.change_group(%Group{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"group" => group_params}) do
case Accounts.create_group(group_params) do
{:ok, group} ->
conn
|> put_flash(:info, "Group created successfully.")
|> redirect(to: group_path(conn, :show, group))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
group = Accounts.get_group!(id)
render(conn, "show.html", group: group)
end
def edit(conn, %{"id" => id}) do
group = Accounts.get_group!(id)
changeset = Accounts.change_group(group)
render(conn, "edit.html", group: group, changeset: changeset)
end
def update(conn, %{"id" => id, "group" => group_params}) do
group = Accounts.get_group!(id)
case Accounts.update_group(group, group_params) do
{:ok, group} ->
conn
|> put_flash(:info, "Group updated successfully.")
|> redirect(to: group_path(conn, :show, group))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", group: group, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
group = Accounts.get_group!(id)
{:ok, _group} = Accounts.delete_group(group)
conn
|> put_flash(:info, "Group deleted successfully.")
|> redirect(to: group_path(conn, :index))
end
end