update things
This commit is contained in:
parent
984a193c5d
commit
b2f2f57029
6 changed files with 27 additions and 9 deletions
|
|
@ -35,7 +35,7 @@ defmodule Zoeyscomputer.Gists do
|
|||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_gist!(id), do: Repo.get!(Gist, id)
|
||||
def get_gist!(id), do: Repo.get!(Gist, id) |> Repo.preload([:author])
|
||||
|
||||
@doc """
|
||||
Creates a gist.
|
||||
|
|
@ -49,7 +49,11 @@ defmodule Zoeyscomputer.Gists do
|
|||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_gist(attrs \\ %{}) 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)
|
||||
|> Repo.insert()
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ defmodule Zoeyscomputer.Gists.Gist do
|
|||
@doc false
|
||||
def changeset(gist, attrs) do
|
||||
gist
|
||||
|> cast(attrs, [:code, :lang, :title, :desc])
|
||||
|> validate_required([:code, :lang, :title])
|
||||
|> cast(attrs, [:code, :lang, :title, :desc, :author_id])
|
||||
|> validate_required([:code, :lang, :title, :author_id])
|
||||
|> put_new_id()
|
||||
end
|
||||
|
||||
defp put_new_id(changeset) do
|
||||
IO.puts("assigning new id")
|
||||
|
||||
case get_field(changeset, :id) do
|
||||
nil -> put_change(changeset, :id, IdGenerator.generate(7))
|
||||
_id -> changeset
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue