Allow items without dates
This commit is contained in:
parent
fbe98c2e66
commit
740e0e7fca
|
@ -5,7 +5,7 @@ defmodule Frenzy.Item do
|
|||
alias FrenzyWeb.Endpoint
|
||||
|
||||
def to_fever(item) do
|
||||
%{
|
||||
res = %{
|
||||
id: item.id,
|
||||
feed_id: item.feed_id,
|
||||
title: item.title,
|
||||
|
@ -13,24 +13,34 @@ defmodule Frenzy.Item do
|
|||
html: item.content,
|
||||
url: item.url,
|
||||
is_saved: 0,
|
||||
is_read: if(item.read, do: 1, else: 0),
|
||||
created_on_time: Timex.to_unix(item.date)
|
||||
is_read: if(item.read, do: 1, else: 0)
|
||||
}
|
||||
|
||||
if item.date do
|
||||
Map.put(res, :created_on_time, Timex.to_unix(item.date))
|
||||
else
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
def to_fervor(item) do
|
||||
%{
|
||||
res = %{
|
||||
id: item.id,
|
||||
feed_id: item.feed_id,
|
||||
title: item.title,
|
||||
author: item.creator,
|
||||
created_at: DateTime.to_iso8601(item.date),
|
||||
content: item.content,
|
||||
url: item.url,
|
||||
service_url:
|
||||
Application.get_env(:frenzy, :base_url) <> Routes.item_path(Endpoint, :show, item.id),
|
||||
read: item.read
|
||||
}
|
||||
|
||||
if item.date do
|
||||
Map.put(res, :created_at, DateTime.to_iso8601(item.date))
|
||||
else
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
schema "items" do
|
||||
|
@ -53,7 +63,7 @@ defmodule Frenzy.Item do
|
|||
__meta__: Ecto.Schema.Metadata.t(),
|
||||
id: integer() | nil,
|
||||
content: String.t(),
|
||||
date: DateTime.t(),
|
||||
date: DateTime.t() | nil,
|
||||
creator: String.t(),
|
||||
guid: String.t(),
|
||||
url: String.t(),
|
||||
|
|
|
@ -14,11 +14,23 @@ defmodule Frenzy.Task.CreateItem do
|
|||
|
||||
Logger.debug("Creating item for #{url}")
|
||||
|
||||
date =
|
||||
entry.date
|
||||
|> Timex.Timezone.convert(:utc)
|
||||
|> case do
|
||||
{:error, reason} ->
|
||||
Logger.debug("Couldn't convert date '#{entry.date}' to UTC: #{reason}")
|
||||
nil
|
||||
|
||||
utc_date ->
|
||||
DateTime.truncate(utc_date, :second)
|
||||
end
|
||||
|
||||
item_params = %{
|
||||
guid: entry.guid,
|
||||
title: entry.title,
|
||||
url: url,
|
||||
date: entry.date |> Timex.Timezone.convert(:utc) |> DateTime.truncate(:second),
|
||||
date: date,
|
||||
creator: "",
|
||||
content: entry.content
|
||||
}
|
||||
|
|
|
@ -25,8 +25,10 @@
|
|||
<a href="<%= Routes.item_path(@conn, :show, item.id) %>"><%= item.title || "(Untitled)" %></a>
|
||||
</td>
|
||||
<td>
|
||||
<% {:ok, date} = Timex.format(item.date, "{YYYY}-{M}-{D} {h12}:{m} {AM}") %>
|
||||
<%= date %>
|
||||
<% if item.date do %>
|
||||
<% {:ok, date} = Timex.format(item.date, "{YYYY}-{M}-{D} {h12}:{m} {AM}") %>
|
||||
<%= date %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue