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
|
import Ecto.Query, warn: false
|
||||||
alias Zoeyscomputer.Repo
|
alias Zoeyscomputer.Repo
|
||||||
|
|
||||||
|
alias Zoeyscomputer.Users.User
|
||||||
alias Zoeyscomputer.Gists.Gist
|
alias Zoeyscomputer.Gists.Gist
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
@ -21,6 +22,12 @@ defmodule Zoeyscomputer.Gists do
|
||||||
Repo.all(Gist)
|
Repo.all(Gist)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list_gists_for_user(%User{} = user) do
|
||||||
|
Gist
|
||||||
|
|> where([a], a.author_id == ^user.id)
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Gets a single gist.
|
Gets a single gist.
|
||||||
|
|
||||||
|
|
@ -52,7 +59,6 @@ defmodule Zoeyscomputer.Gists do
|
||||||
def create_gist(user, attrs \\ %{}) do
|
def create_gist(user, attrs \\ %{}) do
|
||||||
IO.puts("hereo")
|
IO.puts("hereo")
|
||||||
attrs = Map.put(attrs, "author_id", user.id)
|
attrs = Map.put(attrs, "author_id", user.id)
|
||||||
IO.inspect(attrs)
|
|
||||||
|
|
||||||
%Gist{}
|
%Gist{}
|
||||||
|> Gist.changeset(attrs)
|
|> Gist.changeset(attrs)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ defmodule ZoeyscomputerWeb.GistLive.Index do
|
||||||
socket = socket |> assign(:current_user, socket.assigns.current_user)
|
socket = socket |> assign(:current_user, socket.assigns.current_user)
|
||||||
|
|
||||||
if connected?(socket) && socket.assigns.current_user do
|
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
|
else
|
||||||
{:ok, stream(socket, :gists, [])}
|
{:ok, stream(socket, :gists, [])}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue