diff --git a/lib/zoeyscomputer/gists.ex b/lib/zoeyscomputer/gists.ex index 01aa7e4..7f31bed 100644 --- a/lib/zoeyscomputer/gists.ex +++ b/lib/zoeyscomputer/gists.ex @@ -6,6 +6,7 @@ defmodule Zoeyscomputer.Gists do import Ecto.Query, warn: false alias Zoeyscomputer.Repo + alias Zoeyscomputer.Users.User alias Zoeyscomputer.Gists.Gist @doc """ @@ -21,6 +22,12 @@ defmodule Zoeyscomputer.Gists do Repo.all(Gist) end + def list_gists_for_user(%User{} = user) do + Gist + |> where([a], a.author_id == ^user.id) + |> Repo.all() + end + @doc """ Gets a single gist. @@ -52,7 +59,6 @@ defmodule Zoeyscomputer.Gists do def create_gist(user, attrs \\ %{}) do IO.puts("hereo") attrs = Map.put(attrs, "author_id", user.id) - IO.inspect(attrs) %Gist{} |> Gist.changeset(attrs) diff --git a/lib/zoeyscomputer_web/live/gist_live/index.ex b/lib/zoeyscomputer_web/live/gist_live/index.ex index c87d739..ed68a8e 100644 --- a/lib/zoeyscomputer_web/live/gist_live/index.ex +++ b/lib/zoeyscomputer_web/live/gist_live/index.ex @@ -9,7 +9,7 @@ defmodule ZoeyscomputerWeb.GistLive.Index do socket = socket |> assign(:current_user, socket.assigns.current_user) if connected?(socket) && socket.assigns.current_user do - {:ok, stream(socket, :gists, Gists.list_gists())} + {:ok, stream(socket, :gists, Gists.list_gists_for_user(socket.assigns.current_user))} else {:ok, stream(socket, :gists, [])} end