this repo has no description
1defmodule EslHn do
2 @moduledoc """
3 EslHn keeps the contexts that define your domain
4 and business logic.
5
6 Contexts are also responsible for managing your data, regardless
7 if it comes from the database, an external API or others.
8 """
9
10 alias EslHn.Cache
11
12 def all(page \\ 1, per_page \\ 10) do
13 skip = per_page * (page - 1)
14
15 ids = Cache.get(EslHn, :index, [])
16
17 ids
18 |> Enum.drop(skip)
19 |> Enum.take(per_page)
20 |> Enum.map(&Cache.get(EslHn, &1))
21 end
22
23 def story(id) do
24 Cache.fetch(EslHn, id)
25 end
26
27 def broadcast_new(stories) do
28 Phoenix.PubSub.broadcast(EslHn.PubSub, "hn:new", {:new_stories, stories})
29 end
30
31 def subscribe_new do
32 Phoenix.PubSub.subscribe(EslHn.PubSub, "hn:new")
33 end
34end