mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-26 01:38:36 +00:00
e14007bac5
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
42 lines
1.2 KiB
Elixir
42 lines
1.2 KiB
Elixir
defmodule EventosWeb.CommentController do
|
|
use EventosWeb, :controller
|
|
|
|
alias Eventos.Events
|
|
alias Eventos.Events.Comment
|
|
|
|
action_fallback EventosWeb.FallbackController
|
|
|
|
def index(conn, _params) do
|
|
comments = Events.list_comments()
|
|
render(conn, "index.json", comments: comments)
|
|
end
|
|
|
|
def create(conn, %{"comment" => comment_params}) do
|
|
with {:ok, %Comment{} = comment} <- Events.create_comment(comment_params) do
|
|
conn
|
|
|> put_status(:created)
|
|
|> put_resp_header("location", comment_path(conn, :show, comment))
|
|
|> render("show.json", comment: comment)
|
|
end
|
|
end
|
|
|
|
def show(conn, %{"id" => id}) do
|
|
comment = Events.get_comment!(id)
|
|
render(conn, "show.json", comment: comment)
|
|
end
|
|
|
|
def update(conn, %{"id" => id, "comment" => comment_params}) do
|
|
comment = Events.get_comment!(id)
|
|
|
|
with {:ok, %Comment{} = comment} <- Events.update_comment(comment, comment_params) do
|
|
render(conn, "show.json", comment: comment)
|
|
end
|
|
end
|
|
|
|
def delete(conn, %{"id" => id}) do
|
|
comment = Events.get_comment!(id)
|
|
with {:ok, %Comment{}} <- Events.delete_comment(comment) do
|
|
send_resp(conn, :no_content, "")
|
|
end
|
|
end
|
|
end
|