mobilizon.chapril.org-mobil.../lib/eventos_web/controllers/tag_controller.ex

61 lines
1.6 KiB
Elixir

defmodule EventosWeb.TagController do
use EventosWeb, :controller
alias Eventos.Events
alias Eventos.Events.Tag
def index(conn, _params) do
tags = Events.list_tags()
render(conn, "index.html", tags: tags)
end
def new(conn, _params) do
changeset = Events.change_tag(%Tag{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"tag" => tag_params}) do
case Events.create_tag(tag_params) do
{:ok, tag} ->
conn
|> put_flash(:info, "Tag created successfully.")
|> redirect(to: tag_path(conn, :show, tag))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
tag = Events.get_tag!(id)
render(conn, "show.html", tag: tag)
end
def edit(conn, %{"id" => id}) do
tag = Events.get_tag!(id)
changeset = Events.change_tag(tag)
render(conn, "edit.html", tag: tag, changeset: changeset)
end
def update(conn, %{"id" => id, "tag" => tag_params}) do
tag = Events.get_tag!(id)
case Events.update_tag(tag, tag_params) do
{:ok, tag} ->
conn
|> put_flash(:info, "Tag updated successfully.")
|> redirect(to: tag_path(conn, :show, tag))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", tag: tag, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
tag = Events.get_tag!(id)
{:ok, _tag} = Events.delete_tag(tag)
conn
|> put_flash(:info, "Tag deleted successfully.")
|> redirect(to: tag_path(conn, :index))
end
end