Compare commits

...

3 Commits

14 changed files with 79 additions and 69 deletions

View File

@ -15,13 +15,13 @@
</div>
<div class="flex items-center gap-4">
<.link
href={~p"/channels"}
href={~p"/admin/channels"}
class="text-[0.8125rem] font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
>
Channels
</.link>
<.link
href={~p"/notes"}
href={~p"/admin/notes"}
class="text-[0.8125rem] font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
>
Notes

View File

@ -19,7 +19,7 @@ defmodule ChiyaWeb.ChannelController do
{:ok, channel} ->
conn
|> put_flash(:info, "Channel created successfully.")
|> redirect(to: ~p"/channels/#{channel}")
|> redirect(to: ~p"/admin/channels/#{channel}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :new, changeset: changeset)
@ -44,7 +44,7 @@ defmodule ChiyaWeb.ChannelController do
{:ok, channel} ->
conn
|> put_flash(:info, "Channel updated successfully.")
|> redirect(to: ~p"/channels/#{channel}")
|> redirect(to: ~p"/admin/channels/#{channel}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :edit, channel: channel, changeset: changeset)
@ -57,6 +57,6 @@ defmodule ChiyaWeb.ChannelController do
conn
|> put_flash(:info, "Channel deleted successfully.")
|> redirect(to: ~p"/channels")
|> redirect(to: ~p"/admin/channels")
end
end

View File

@ -3,6 +3,6 @@
<:subtitle>Use this form to manage channel records in your database.</:subtitle>
</.header>
<.channel_form changeset={@changeset} action={~p"/channels/#{@channel}"} />
<.channel_form changeset={@changeset} action={~p"/admin/channels/#{@channel}"} />
<.back navigate={~p"/channels"}>Back to channels</.back>
<.back navigate={~p"/admin/channels"}>Back to channels</.back>

View File

@ -1,24 +1,24 @@
<.header>
Listing Channels
<:actions>
<.link href={~p"/channels/new"}>
<.link href={~p"/admin/channels/new"}>
<.button>New Channel</.button>
</.link>
</:actions>
</.header>
<.table id="channels" rows={@channels} row_click={&JS.navigate(~p"/channels/#{&1}")}>
<.table id="channels" rows={@channels} row_click={&JS.navigate(~p"/admin/channels/#{&1}")}>
<:col :let={channel} label="Name"><%= channel.name %></:col>
<:col :let={channel} label="Visibility"><%= channel.visibility %></:col>
<:col :let={channel} label="Slug"><%= channel.slug %></:col>
<:action :let={channel}>
<div class="sr-only">
<.link navigate={~p"/channels/#{channel}"}>Show</.link>
<.link navigate={~p"/admin/channels/#{channel}"}>Show</.link>
</div>
<.link navigate={~p"/channels/#{channel}/edit"}>Edit</.link>
<.link navigate={~p"/admin/channels/#{channel}/edit"}>Edit</.link>
</:action>
<:action :let={channel}>
<.link href={~p"/channels/#{channel}"} method="delete" data-confirm="Are you sure?">
<.link href={~p"/admin/channels/#{channel}"} method="delete" data-confirm="Are you sure?">
Delete
</.link>
</:action>

View File

@ -3,6 +3,6 @@
<:subtitle>Use this form to manage channel records in your database.</:subtitle>
</.header>
<.channel_form changeset={@changeset} action={~p"/channels"} />
<.channel_form changeset={@changeset} action={~p"/admin/channels"} />
<.back navigate={~p"/channels"}>Back to channels</.back>
<.back navigate={~p"/admin/channels"}>Back to channels</.back>

View File

@ -2,7 +2,7 @@
Channel <%= @channel.id %>
<:subtitle>This is a channel record from your database.</:subtitle>
<:actions>
<.link href={~p"/channels/#{@channel}/edit"}>
<.link href={~p"/admin/channels/#{@channel}/edit"}>
<.button>Edit channel</.button>
</.link>
</:actions>
@ -15,4 +15,4 @@
<:item title="Slug"><%= @channel.slug %></:item>
</.list>
<.back navigate={~p"/channels"}>Back to channels</.back>
<.back navigate={~p"/admin/channels"}>Back to channels</.back>

View File

@ -21,7 +21,7 @@ defmodule ChiyaWeb.NoteController do
{:ok, note} ->
conn
|> put_flash(:info, "Note created successfully.")
|> redirect(to: ~p"/notes/#{note}")
|> redirect(to: ~p"/admin/notes/#{note}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :new, changeset: changeset, channels: to_channel_options())
@ -47,7 +47,7 @@ defmodule ChiyaWeb.NoteController do
{:ok, note} ->
conn
|> put_flash(:info, "Note updated successfully.")
|> redirect(to: ~p"/notes/#{note}")
|> redirect(to: ~p"/admin/notes/#{note}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :edit, note: note, changeset: changeset, channels: to_channel_options())
@ -60,7 +60,7 @@ defmodule ChiyaWeb.NoteController do
conn
|> put_flash(:info, "Note deleted successfully.")
|> redirect(to: ~p"/notes")
|> redirect(to: ~p"/admin/notes")
end
defp from_channel_ids(note_params) do

View File

@ -3,6 +3,6 @@
<:subtitle>Use this form to manage note records in your database.</:subtitle>
</.header>
<.note_form changeset={@changeset} action={~p"/notes/#{@note}"} channels={@channels} />
<.note_form changeset={@changeset} action={~p"/admin/notes/#{@note}"} channels={@channels} />
<.back navigate={~p"/notes"}>Back to notes</.back>
<.back navigate={~p"/admin/notes"}>Back to notes</.back>

View File

@ -1,13 +1,13 @@
<.header>
Listing Notes
<:actions>
<.link href={~p"/notes/new"}>
<.link href={~p"/admin/notes/new"}>
<.button>New Note</.button>
</.link>
</:actions>
</.header>
<.table id="notes" rows={@notes} row_click={&JS.navigate(~p"/notes/#{&1}")}>
<.table id="notes" rows={@notes} row_click={&JS.navigate(~p"/admin/notes/#{&1}")}>
<:col :let={note} label="Name"><%= note.name %></:col>
<:col :let={note} label="Slug"><%= note.slug %></:col>
<:col :let={note} label="Published at"><%= note.published_at %></:col>
@ -15,12 +15,12 @@
<:col :let={note} label="Url"><%= note.url %></:col>
<:action :let={note}>
<div class="sr-only">
<.link navigate={~p"/notes/#{note}"}>Show</.link>
<.link navigate={~p"/admin/notes/#{note}"}>Show</.link>
</div>
<.link navigate={~p"/notes/#{note}/edit"}>Edit</.link>
<.link navigate={~p"/admin/notes/#{note}/edit"}>Edit</.link>
</:action>
<:action :let={note}>
<.link href={~p"/notes/#{note}"} method="delete" data-confirm="Are you sure?">
<.link href={~p"/admin/notes/#{note}"} method="delete" data-confirm="Are you sure?">
Delete
</.link>
</:action>

View File

@ -3,6 +3,6 @@
<:subtitle>Use this form to manage note records in your database.</:subtitle>
</.header>
<.note_form changeset={@changeset} action={~p"/notes"} channels={@channels} />
<.note_form changeset={@changeset} action={~p"/admin/notes"} channels={@channels} />
<.back navigate={~p"/notes"}>Back to notes</.back>
<.back navigate={~p"/admin/notes"}>Back to notes</.back>

View File

@ -2,7 +2,7 @@
Note <%= @note.id %>
<:subtitle>This is a note record from your database.</:subtitle>
<:actions>
<.link href={~p"/notes/#{@note}/edit"}>
<.link href={~p"/admin/notes/#{@note}/edit"}>
<.button>Edit note</.button>
</.link>
</:actions>
@ -17,4 +17,4 @@
<:item title="Url"><%= @note.url %></:item>
</.list>
<.back navigate={~p"/notes"}>Back to notes</.back>
<.back navigate={~p"/admin/notes"}>Back to notes</.back>

View File

@ -21,9 +21,6 @@ defmodule ChiyaWeb.Router do
pipe_through :browser
get "/", PageController, :home
resources "/channels", ChannelController
resources "/notes", NoteController
end
# Other scopes may use custom stacks.
@ -48,6 +45,15 @@ defmodule ChiyaWeb.Router do
end
end
## Administrator routes
scope "/admin", ChiyaWeb do
pipe_through [:browser, :require_authenticated_user]
resources "/channels", ChannelController
resources "/notes", NoteController
end
## Authentication routes
scope "/", ChiyaWeb do

View File

@ -17,33 +17,35 @@ defmodule ChiyaWeb.ChannelControllerTest do
}
@invalid_attrs %{content: nil, name: nil, slug: nil, visibility: nil}
setup [:register_and_log_in_user]
describe "index" do
test "lists all channels", %{conn: conn} do
conn = get(conn, ~p"/channels")
conn = get(conn, ~p"/admin/channels")
assert html_response(conn, 200) =~ "Listing Channels"
end
end
describe "new channel" do
test "renders form", %{conn: conn} do
conn = get(conn, ~p"/channels/new")
conn = get(conn, ~p"/admin/channels/new")
assert html_response(conn, 200) =~ "New Channel"
end
end
describe "create channel" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post(conn, ~p"/channels", channel: @create_attrs)
conn = post(conn, ~p"/admin/channels", channel: @create_attrs)
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == ~p"/channels/#{id}"
assert redirected_to(conn) == ~p"/admin/channels/#{id}"
conn = get(conn, ~p"/channels/#{id}")
conn = get(conn, ~p"/admin/channels/#{id}")
assert html_response(conn, 200) =~ "Channel #{id}"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, ~p"/channels", channel: @invalid_attrs)
conn = post(conn, ~p"/admin/channels", channel: @invalid_attrs)
assert html_response(conn, 200) =~ "New Channel"
end
end
@ -52,7 +54,7 @@ defmodule ChiyaWeb.ChannelControllerTest do
setup [:create_channel]
test "renders form for editing chosen channel", %{conn: conn, channel: channel} do
conn = get(conn, ~p"/channels/#{channel}/edit")
conn = get(conn, ~p"/admin/channels/#{channel}/edit")
assert html_response(conn, 200) =~ "Edit Channel"
end
end
@ -61,15 +63,15 @@ defmodule ChiyaWeb.ChannelControllerTest do
setup [:create_channel]
test "redirects when data is valid", %{conn: conn, channel: channel} do
conn = put(conn, ~p"/channels/#{channel}", channel: @update_attrs)
assert redirected_to(conn) == ~p"/channels/#{channel}"
conn = put(conn, ~p"/admin/channels/#{channel}", channel: @update_attrs)
assert redirected_to(conn) == ~p"/admin/channels/#{channel}"
conn = get(conn, ~p"/channels/#{channel}")
conn = get(conn, ~p"/admin/channels/#{channel}")
assert html_response(conn, 200) =~ "some updated content"
end
test "renders errors when data is invalid", %{conn: conn, channel: channel} do
conn = put(conn, ~p"/channels/#{channel}", channel: @invalid_attrs)
conn = put(conn, ~p"/admin/channels/#{channel}", channel: @invalid_attrs)
assert html_response(conn, 200) =~ "Edit Channel"
end
end
@ -78,11 +80,11 @@ defmodule ChiyaWeb.ChannelControllerTest do
setup [:create_channel]
test "deletes chosen channel", %{conn: conn, channel: channel} do
conn = delete(conn, ~p"/channels/#{channel}")
assert redirected_to(conn) == ~p"/channels"
conn = delete(conn, ~p"/admin/channels/#{channel}")
assert redirected_to(conn) == ~p"/admin/channels"
assert_error_sent 404, fn ->
get(conn, ~p"/channels/#{channel}")
get(conn, ~p"/admin/channels/#{channel}")
end
end
end

View File

@ -21,33 +21,35 @@ defmodule ChiyaWeb.NoteControllerTest do
}
@invalid_attrs %{content: nil, kind: nil, name: nil, published_at: nil, slug: nil, url: nil}
setup [:register_and_log_in_user]
describe "index" do
test "lists all notes", %{conn: conn} do
conn = get(conn, ~p"/notes")
conn = get(conn, ~p"/admin/notes")
assert html_response(conn, 200) =~ "Listing Notes"
end
end
describe "new note" do
test "renders form", %{conn: conn} do
conn = get(conn, ~p"/notes/new")
conn = get(conn, ~p"/admin/notes/new")
assert html_response(conn, 200) =~ "New Note"
end
end
describe "create note" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post(conn, ~p"/notes", note: @create_attrs)
conn = post(conn, ~p"/admin/notes", note: @create_attrs)
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == ~p"/notes/#{id}"
assert redirected_to(conn) == ~p"/admin/notes/#{id}"
conn = get(conn, ~p"/notes/#{id}")
conn = get(conn, ~p"/admin/notes/#{id}")
assert html_response(conn, 200) =~ "Note #{id}"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, ~p"/notes", note: @invalid_attrs)
conn = post(conn, ~p"/admin/notes", note: @invalid_attrs)
assert html_response(conn, 200) =~ "New Note"
end
end
@ -57,12 +59,12 @@ defmodule ChiyaWeb.NoteControllerTest do
test "redirects to show when selecting a channel", %{conn: conn, channel: channel} do
attrs = Map.put_new(@create_attrs, :channels, [to_string(channel.id)])
conn = post(conn, ~p"/notes", note: attrs)
conn = post(conn, ~p"/admin/notes", note: attrs)
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == ~p"/notes/#{id}"
assert redirected_to(conn) == ~p"/admin/notes/#{id}"
conn = get(conn, ~p"/notes/#{id}")
conn = get(conn, ~p"/admin/notes/#{id}")
assert html_response(conn, 200) =~ "Note #{id}"
end
end
@ -71,7 +73,7 @@ defmodule ChiyaWeb.NoteControllerTest do
setup [:create_note]
test "renders form for editing chosen note", %{conn: conn, note: note} do
conn = get(conn, ~p"/notes/#{note}/edit")
conn = get(conn, ~p"/admin/notes/#{note}/edit")
assert html_response(conn, 200) =~ "Edit Note"
end
end
@ -80,15 +82,15 @@ defmodule ChiyaWeb.NoteControllerTest do
setup [:create_note]
test "redirects when data is valid", %{conn: conn, note: note} do
conn = put(conn, ~p"/notes/#{note}", note: @update_attrs)
assert redirected_to(conn) == ~p"/notes/#{note}"
conn = put(conn, ~p"/admin/notes/#{note}", note: @update_attrs)
assert redirected_to(conn) == ~p"/admin/notes/#{note}"
conn = get(conn, ~p"/notes/#{note}")
conn = get(conn, ~p"/admin/notes/#{note}")
assert html_response(conn, 200) =~ "some updated content"
end
test "renders errors when data is invalid", %{conn: conn, note: note} do
conn = put(conn, ~p"/notes/#{note}", note: @invalid_attrs)
conn = put(conn, ~p"/admin/notes/#{note}", note: @invalid_attrs)
assert html_response(conn, 200) =~ "Edit Note"
end
end
@ -103,14 +105,14 @@ defmodule ChiyaWeb.NoteControllerTest do
channel2: channel2
} do
attrs = Map.put_new(@update_attrs, :channels, [to_string(channel.id)])
conn = put(conn, ~p"/notes/#{note}", note: attrs)
assert redirected_to(conn) == ~p"/notes/#{note}"
conn = put(conn, ~p"/admin/notes/#{note}", note: attrs)
assert redirected_to(conn) == ~p"/admin/notes/#{note}"
attrs = Map.put_new(@update_attrs, :channels, [to_string(channel2.id)])
conn = put(conn, ~p"/notes/#{note}", note: attrs)
assert redirected_to(conn) == ~p"/notes/#{note}"
conn = put(conn, ~p"/admin/notes/#{note}", note: attrs)
assert redirected_to(conn) == ~p"/admin/notes/#{note}"
conn = get(conn, ~p"/notes/#{note}")
conn = get(conn, ~p"/admin/notes/#{note}")
assert html_response(conn, 200) =~ "some updated content"
end
end
@ -119,11 +121,11 @@ defmodule ChiyaWeb.NoteControllerTest do
setup [:create_note]
test "deletes chosen note", %{conn: conn, note: note} do
conn = delete(conn, ~p"/notes/#{note}")
assert redirected_to(conn) == ~p"/notes"
conn = delete(conn, ~p"/admin/notes/#{note}")
assert redirected_to(conn) == ~p"/admin/notes"
assert_error_sent 404, fn ->
get(conn, ~p"/notes/#{note}")
get(conn, ~p"/admin/notes/#{note}")
end
end
end