debianize-mobilizon/lib/eventos_web/controllers/group_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

46 lines
1.1 KiB
Elixir

defmodule EventosWeb.GroupController do
@moduledoc """
Controller for Groups
"""
use EventosWeb, :controller
alias Eventos.Groups
alias Eventos.Groups.Group
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
groups = Groups.list_groups()
render(conn, "index.json", groups: groups)
end
def create(conn, %{"group" => group_params}) do
with {:ok, %Group{} = group} <- Groups.create_group(group_params) do
conn
|> put_status(:created)
|> put_resp_header("location", group_path(conn, :show, group))
|> render("show.json", group: group)
end
end
def show(conn, %{"id" => id}) do
group = Groups.get_group!(id)
render(conn, "show.json", group: group)
end
def update(conn, %{"id" => id, "group" => group_params}) do
group = Groups.get_group!(id)
with {:ok, %Group{} = group} <- Groups.update_group(group, group_params) do
render(conn, "show.json", group: group)
end
end
def delete(conn, %{"id" => id}) do
group = Groups.get_group!(id)
with {:ok, %Group{}} <- Groups.delete_group(group) do
send_resp(conn, :no_content, "")
end
end
end