~afontaine/home

65e206364bbee3db9f3af814c3061eacd3f46e13 — Andrew Fontaine 7 months ago 2351b1c
Add safety to editing posts without adding tags

Now tags shouldn't be overwritten when changing something not tag
related.
2 files changed, 2 insertions(+), 2 deletions(-)

M apps/blog/lib/blog/content.ex
M apps/blog/lib/blog/content/post.ex
M apps/blog/lib/blog/content.ex => apps/blog/lib/blog/content.ex +1 -1
@@ 66,7 66,7 @@ defmodule Blog.Content do
  def create_post(%{} = post) do
    %Post{}
    |> Repo.preload(:tags)
    |> Post.changeset(%{post | tags: fetch_tags(post.tags)})
    |> Post.changeset(%{post | tags: fetch_tags(Map.get(post, :tags, []))})
    |> Repo.insert()
  end


M apps/blog/lib/blog/content/post.ex => apps/blog/lib/blog/content/post.ex +1 -1
@@ 24,6 24,6 @@ defmodule Blog.Content.Post do
    |> validate_required([:subject, :text, :message_id, :author])
    |> unique_constraint(:message_id)
    |> slugify(:subject)
    |> put_assoc(:tags, attrs.tags)
    |> put_assoc(:tags, Map.get(attrs, :tags, post.tags))
  end
end