Fix error when trying to change read status of tombstones

This commit is contained in:
Shadowfacts 2022-01-31 14:31:16 -05:00
parent f0299639e2
commit 933a157278
1 changed files with 10 additions and 6 deletions

View File

@ -56,14 +56,18 @@ defmodule FrenzyWeb.Fervor.ItemsController do
json(conn, Item.to_fervor(item))
end
def mark_item(conn, changes) do
defp mark_item(conn, changes) do
item = conn.assigns[:item] |> Repo.preload(:feed)
changeset = Item.changeset(item, changes)
{:ok, item} = Repo.update(changeset)
if changeset.valid? do
{:ok, item} = Repo.update(changeset)
json(conn, Item.to_fervor(item))
json(conn, Item.to_fervor(item))
else
json(conn, Item.to_fervor(item))
end
end
def read_specific_item(conn, _params) do
@ -74,7 +78,7 @@ defmodule FrenzyWeb.Fervor.ItemsController do
mark_item(conn, %{read: false})
end
def mark_multiple_items(conn, %{"ids" => ids}, changes) do
defp mark_multiple_items(conn, %{"ids" => ids}, changes) do
user = conn.assigns[:user] |> Repo.preload(groups: [:feeds])
feeds = Enum.flat_map(user.groups, fn g -> g.feeds end)
@ -90,7 +94,7 @@ defmodule FrenzyWeb.Fervor.ItemsController do
Repo.get(Item, id)
end)
|> Enum.filter(fn item ->
Enum.any?(feeds, fn f -> f.id == item.feed_id end)
Enum.any?(feeds, fn f -> f.id == item.feed_id end) && !item.tombstone
end)
|> Enum.map(fn item ->
item = Repo.preload(item, :feed)
@ -106,7 +110,7 @@ defmodule FrenzyWeb.Fervor.ItemsController do
json(conn, read_ids)
end
def mark_multiple_items(conn, _params, _changes) do
defp mark_multiple_items(conn, _params, _changes) do
conn
|> put_status(400)
|> json(%{error: "No items provided."})