chiya/lib/chiya_web/controllers/comment_controller.ex

26 lines
728 B
Elixir
Raw Permalink Normal View History

2023-04-30 13:35:22 +02:00
defmodule ChiyaWeb.CommentController do
use ChiyaWeb, :controller
2023-05-09 16:18:10 +02:00
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
2023-04-30 13:35:22 +02:00
def create(conn, %{"slug" => note_slug, "note_comment" => comment_params}) do
2023-06-02 07:07:22 +02:00
_note = Chiya.Notes.get_note_by_slug_preloaded!(note_slug)
2023-04-30 13:35:22 +02:00
case Chiya.Notes.create_note_comment(comment_params) do
{:ok, _comment} ->
2023-06-02 07:07:22 +02:00
redirect(conn, to: ~p"/note/#{note_slug}?error=0")
2023-04-30 13:35:22 +02:00
2023-06-02 07:10:59 +02:00
{:error, _changeset} ->
2023-06-02 07:07:22 +02:00
redirect(conn, to: ~p"/note/#{note_slug}?error=1")
2023-04-30 13:35:22 +02:00
end
end
end