show only your gists
This commit is contained in:
parent
b2f2f57029
commit
221c3ae76c
2 changed files with 8 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue