55 lines
1.3 KiB
Elixir
55 lines
1.3 KiB
Elixir
defmodule Frenzy.Feed do
|
|
use Ecto.Schema
|
|
import Ecto.Changeset
|
|
alias FrenzyWeb.Router.Helpers, as: Routes
|
|
alias FrenzyWeb.Endpoint
|
|
|
|
def to_fever(feed) do
|
|
%{
|
|
id: feed.id,
|
|
favicon_id: feed.id,
|
|
title: feed.title,
|
|
url: feed.feed_url,
|
|
site_url: feed.site_url,
|
|
last_updated_on_time: Timex.to_unix(feed.last_updated),
|
|
is_spark: false
|
|
}
|
|
end
|
|
|
|
def to_fervor(feed) do
|
|
%{
|
|
id: feed.id,
|
|
title: feed.title,
|
|
url: feed.site_url,
|
|
feed_url: feed.feed_url,
|
|
service_url:
|
|
Application.get_env(:frenzy, :base_url) <> Routes.feed_path(Endpoint, :show, feed.id),
|
|
last_updated: DateTime.to_iso8601(feed.last_updated),
|
|
group_ids: [feed.group_id]
|
|
}
|
|
end
|
|
|
|
schema "feeds" do
|
|
field :feed_url, :string
|
|
field :last_updated, :utc_datetime
|
|
field :site_url, :string
|
|
field :title, :string
|
|
field :filter_enabled, :boolean
|
|
|
|
belongs_to :group, Frenzy.Group
|
|
|
|
has_many :items, Frenzy.Item, on_delete: :delete_all
|
|
has_one :filter, Frenzy.Filter, on_delete: :delete_all
|
|
|
|
timestamps()
|
|
end
|
|
|
|
@doc false
|
|
def changeset(feed, attrs) do
|
|
feed
|
|
|> cast(attrs, [:title, :feed_url, :site_url, :last_updated, :filter_enabled])
|
|
|> cast_assoc(:filter, required: true)
|
|
|> validate_required([:feed_url, :filter])
|
|
end
|
|
end
|