Skip to content

Commit ebd9f7f

Browse files
committed
feat(pastes): add new page to show owned pastes
Signed-off-by: SphericalKat <amolele@gmail.com>
1 parent f0efa78 commit ebd9f7f

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

lib/ketbin/pastes.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ defmodule Ketbin.Pastes do
2121
Repo.all(Paste)
2222
end
2323

24+
def list_pastes_by_user(user_id) do
25+
Repo.all(from(p in Paste, where: p.belongs_to == ^user_id))
26+
end
27+
2428
@doc """
2529
Gets a single paste.
2630

lib/ketbin_web/controllers/page_controller.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,9 @@ defmodule KetbinWeb.PageController do
134134
render(conn, "edit.html", paste: paste, changeset: changeset)
135135
end
136136
end
137+
138+
def pastes(%{assigns: %{current_user: current_user}} = conn, _params) do
139+
pastes = Pastes.list_pastes_by_user(current_user.id)
140+
render(conn, "pastes.html", pastes: pastes)
141+
end
137142
end

lib/ketbin_web/router.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ defmodule KetbinWeb.Router do
1818
plug :fetch_current_user
1919
end
2020

21+
# scope to ensure user is authenticated
22+
scope "/", KetbinWeb do
23+
pipe_through [:browser, :require_authenticated_user]
24+
25+
get "/pastes", PageController, :pastes
26+
end
27+
2128
scope "/", KetbinWeb do
2229
pipe_through :browser
2330

lib/ketbin_web/templates/layout/_user_menu.html.heex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function toggleDropdown() {
2020
<div id="dropdown" class="hidden right-0 z-50 bg-[#313131] px-4 py-2">
2121
<li><%= link "Settings", to: Routes.user_settings_path(@conn, :edit) %></li>
2222
<li><%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %></li>
23+
<li><%= link "My Pastes", to: Routes.page_path(@conn, :pastes) %></li>
2324
</div>
2425
</div>
2526
<% else %>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="flex relative flex-col w-full h-full">
2+
<ul class="break-word py-4 h-full w-full overflow-y-auto">
3+
<%= for paste <- @pastes do %>
4+
<li class="flex flex-row items-center justify-between">
5+
<a href={ Routes.page_path(@conn, :show, paste) } class="">
6+
https://katb.in/v/<%= paste.id %>
7+
</a>
8+
</li>
9+
<% end %>
10+
</ul>
11+
</div>

0 commit comments

Comments
 (0)