comfycamp/lib/comfycamp_web/controllers/notes_controller.ex

25 lines
688 B
Elixir

defmodule ComfycampWeb.NotesController do
use ComfycampWeb, :controller
alias Comfycamp.Notes
def index(conn, _params) do
notes = Notes.list_notes()
render(conn, :index, page_title: "Заметки", notes: notes)
end
def show(conn, %{"id" => id}) do
note = Notes.get_note!(id)
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
end
end