frenzy/lib/frenzy_web/controllers/item_controller.ex

36 lines
919 B
Elixir
Raw Normal View History

2019-02-11 22:22:35 +00:00
defmodule FrenzyWeb.ItemController do
use FrenzyWeb, :controller
alias Frenzy.{Repo, Feed, Item}
alias FrenzyWeb.Router.Helpers, as: Routes
alias FrenzyWeb.Endpoint
def show(conn, %{"id" => id}) do
item = Repo.get(Item, id)
feed = Repo.get(Feed, item.feed_id)
render(conn, "show.html", %{
item: item,
feed: feed
})
end
def read(conn, %{"id" => id}) do
item = Repo.get(Item, id) |> Repo.preload(:feed)
changeset = Item.changeset(item, %{
read: true,
read_date: Timex.now
})
Repo.update(changeset)
redirect(conn, to: Routes.item_path(Endpoint, :show, id))
end
def unread(conn, %{"id" => id}) do
item = Repo.get(Item, id) |> Repo.preload(:feed)
changeset = Item.changeset(item, %{
read: false,
read_date: nil
})
Repo.update(changeset)
redirect(conn, to: Routes.item_path(Endpoint, :show, id))
end
end