Add all
This commit is contained in:
parent
b35e18cd20
commit
82f55f7afe
80 changed files with 6687 additions and 5 deletions
43
lib/nulla_web/controllers/note_controller.ex
Normal file
43
lib/nulla_web/controllers/note_controller.ex
Normal file
|
@ -0,0 +1,43 @@
|
|||
defmodule NullaWeb.NoteController do
|
||||
use NullaWeb, :controller
|
||||
|
||||
alias Nulla.Notes
|
||||
alias Nulla.Notes.Note
|
||||
|
||||
action_fallback NullaWeb.FallbackController
|
||||
|
||||
def index(conn, _params) do
|
||||
notes = Notes.list_notes()
|
||||
render(conn, :index, notes: notes)
|
||||
end
|
||||
|
||||
def create(conn, %{"note" => note_params}) do
|
||||
with {:ok, %Note{} = note} <- Notes.create_note(note_params) do
|
||||
conn
|
||||
|> put_status(:created)
|
||||
|> put_resp_header("location", ~p"/api/notes/#{note}")
|
||||
|> render(:show, note: note)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
note = Notes.get_note!(id)
|
||||
render(conn, :show, note: note)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, "note" => note_params}) do
|
||||
note = Notes.get_note!(id)
|
||||
|
||||
with {:ok, %Note{} = note} <- Notes.update_note(note, note_params) do
|
||||
render(conn, :show, note: note)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
note = Notes.get_note!(id)
|
||||
|
||||
with {:ok, %Note{}} <- Notes.delete_note(note) do
|
||||
send_resp(conn, :no_content, "")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue