2018-10-11 15:37:39 +00:00
|
|
|
defmodule MobilizonWeb.TagController do
|
2018-01-14 16:56:50 +00:00
|
|
|
@moduledoc """
|
|
|
|
Controller for Tags
|
|
|
|
"""
|
2018-10-11 15:37:39 +00:00
|
|
|
use MobilizonWeb, :controller
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
alias Mobilizon.Events
|
|
|
|
alias Mobilizon.Events.Tag
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
action_fallback(MobilizonWeb.FallbackController)
|
2018-01-13 22:33:03 +00:00
|
|
|
|
2017-12-08 08:58:14 +00:00
|
|
|
def index(conn, _params) do
|
|
|
|
tags = Events.list_tags()
|
2018-01-13 22:33:03 +00:00
|
|
|
render(conn, "index.json", tags: tags)
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create(conn, %{"tag" => tag_params}) do
|
2018-01-13 22:33:03 +00:00
|
|
|
with {:ok, %Tag{} = tag} <- Events.create_tag(tag_params) do
|
|
|
|
conn
|
|
|
|
|> put_status(:created)
|
|
|
|
|> put_resp_header("location", tag_path(conn, :show, tag))
|
|
|
|
|> render("show.json", tag: tag)
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show(conn, %{"id" => id}) do
|
|
|
|
tag = Events.get_tag!(id)
|
2018-01-13 22:33:03 +00:00
|
|
|
render(conn, "show.json", tag: tag)
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update(conn, %{"id" => id, "tag" => tag_params}) do
|
|
|
|
tag = Events.get_tag!(id)
|
|
|
|
|
2018-01-13 22:33:03 +00:00
|
|
|
with {:ok, %Tag{} = tag} <- Events.update_tag(tag, tag_params) do
|
|
|
|
render(conn, "show.json", tag: tag)
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete(conn, %{"id" => id}) do
|
|
|
|
tag = Events.get_tag!(id)
|
2018-07-27 08:45:35 +00:00
|
|
|
|
2018-01-13 22:33:03 +00:00
|
|
|
with {:ok, %Tag{}} <- Events.delete_tag(tag) do
|
|
|
|
send_resp(conn, :no_content, "")
|
|
|
|
end
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
end
|