2024-07-29 16:19:47 +05:00
|
|
|
defmodule ComfycampWeb.NotesController do
|
|
|
|
use ComfycampWeb, :controller
|
|
|
|
|
|
|
|
alias Comfycamp.Notes
|
|
|
|
|
|
|
|
def index(conn, _params) do
|
|
|
|
notes = Notes.list_notes()
|
|
|
|
|
2024-07-29 18:07:44 +05:00
|
|
|
render(conn, :index, page_title: "Заметки", notes: notes)
|
2024-07-29 16:19:47 +05:00
|
|
|
end
|
|
|
|
|
|
|
|
def show(conn, %{"id" => id}) do
|
|
|
|
note = Notes.get_note!(id)
|
|
|
|
|
2024-07-29 20:19:37 +05:00
|
|
|
case Earmark.as_html(note.markdown) do
|
|
|
|
{:ok, note_body, _deprecation_messages} ->
|
|
|
|
render(conn, :show, page_title: note.title, note: note, note_body: note_body)
|
|
|
|
|
|
|
|
{:error, note_body, error_messages} ->
|
|
|
|
conn
|
|
|
|
|> put_flash(:error, error_messages)
|
|
|
|
|> render(:show, page_title: note.title, note: note, note_body: note_body)
|
|
|
|
end
|
2024-07-29 16:19:47 +05:00
|
|
|
end
|
|
|
|
end
|