chiya/lib/chiya_web/controllers/comment_controller.ex

25 lines
716 B
Elixir

defmodule ChiyaWeb.CommentController do
use ChiyaWeb, :controller
def index(conn, _params) do
comments = Chiya.Notes.list_note_comments()
render(conn, comments: comments)
end
def show(conn, %{"id" => comment_id}) do
comment = Chiya.Notes.get_note_comment!(comment_id)
render(conn, comment: comment)
end
def create(conn, %{"slug" => note_slug, "note_comment" => comment_params}) do
note = Chiya.Notes.get_note_by_slug_preloaded!(note_slug)
case Chiya.Notes.create_note_comment(comment_params) do
{:ok, _comment} ->
redirect(conn, to: ~p"/#{note_slug}?error=0")
{:error, changeset} ->
redirect(conn, to: ~p"/#{note_slug}?error=1")
end
end
end