This commit is contained in:
Mirai Kumiko 2025-07-04 10:25:40 +02:00
parent b35e18cd20
commit 82f55f7afe
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
80 changed files with 6687 additions and 5 deletions

View 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