Allow items without dates

This commit is contained in:
Shadowfacts 2020-01-12 21:51:58 -05:00
parent fbe98c2e66
commit 740e0e7fca
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 33 additions and 9 deletions

View File

@ -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(),

View File

@ -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
}

View File

@ -25,8 +25,10 @@
<a href="<%= Routes.item_path(@conn, :show, item.id) %>"><%= item.title || "(Untitled)" %></a>
</td>
<td>
<% if item.date do %>
<% {:ok, date} = Timex.format(item.date, "{YYYY}-{M}-{D} {h12}:{m} {AM}") %>
<%= date %>
<% end %>
</td>
</tr>
<% end %>