2017-12-08 09:58:14 +01:00
|
|
|
defmodule EventosWeb.GroupController do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
Controller for Groups
|
|
|
|
"""
|
2017-12-08 09:58:14 +01:00
|
|
|
use EventosWeb, :controller
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
alias Eventos.Groups
|
|
|
|
alias Eventos.Groups.Group
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
action_fallback EventosWeb.FallbackController
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
def index(conn, _params) do
|
|
|
|
groups = Groups.list_groups()
|
|
|
|
render(conn, "index.json", groups: groups)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create(conn, %{"group" => group_params}) do
|
2018-01-16 19:45:09 +01:00
|
|
|
group_params = Map.put(group_params, "uri", "h")
|
|
|
|
group_params = Map.put(group_params, "url", "h")
|
2018-01-13 23:33:03 +01:00
|
|
|
with {:ok, %Group{} = group} <- Groups.create_group(group_params) do
|
|
|
|
conn
|
|
|
|
|> put_status(:created)
|
|
|
|
|> put_resp_header("location", group_path(conn, :show, group))
|
2018-01-16 19:45:09 +01:00
|
|
|
|> render("show_simple.json", group: group)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show(conn, %{"id" => id}) do
|
2018-01-16 19:45:09 +01:00
|
|
|
group = Groups.get_group_full!(id)
|
2018-01-13 23:33:03 +01:00
|
|
|
render(conn, "show.json", group: group)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update(conn, %{"id" => id, "group" => group_params}) do
|
2018-01-13 23:33:03 +01:00
|
|
|
group = Groups.get_group!(id)
|
|
|
|
|
|
|
|
with {:ok, %Group{} = group} <- Groups.update_group(group, group_params) do
|
2018-01-16 19:45:09 +01:00
|
|
|
render(conn, "show_simple.json", group: group)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete(conn, %{"id" => id}) do
|
2018-01-13 23:33:03 +01:00
|
|
|
group = Groups.get_group!(id)
|
|
|
|
with {:ok, %Group{}} <- Groups.delete_group(group) do
|
|
|
|
send_resp(conn, :no_content, "")
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|