36 lines
919 B
Elixir
36 lines
919 B
Elixir
|
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
|