2018-10-11 17:37:39 +02:00
|
|
|
defmodule MobilizonWeb.CommentController do
|
|
|
|
use MobilizonWeb, :controller
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events
|
|
|
|
alias Mobilizon.Events.Comment
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
action_fallback(MobilizonWeb.FallbackController)
|
2018-05-17 11:32:23 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-06-14 17:25:55 +02:00
|
|
|
def show(conn, %{"uuid" => uuid}) do
|
|
|
|
comment = Events.get_comment_with_uuid!(uuid)
|
2018-05-17 11:32:23 +02:00
|
|
|
render(conn, "show.json", comment: comment)
|
|
|
|
end
|
|
|
|
|
2018-06-14 17:25:55 +02:00
|
|
|
def update(conn, %{"uuid" => uuid, "comment" => comment_params}) do
|
|
|
|
comment = Events.get_comment_with_uuid!(uuid)
|
2018-05-17 11:32:23 +02:00
|
|
|
|
|
|
|
with {:ok, %Comment{} = comment} <- Events.update_comment(comment, comment_params) do
|
|
|
|
render(conn, "show.json", comment: comment)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-14 17:25:55 +02:00
|
|
|
def delete(conn, %{"uuid" => uuid}) do
|
|
|
|
comment = Events.get_comment_with_uuid!(uuid)
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2018-05-17 11:32:23 +02:00
|
|
|
with {:ok, %Comment{}} <- Events.delete_comment(comment) do
|
|
|
|
send_resp(conn, :no_content, "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|