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 def all(page \\ 1, per_page \\ 10) do
11 skip = per_page * (page - 1)
12
13 ids = EslHn.Cache.get(EslHn, :index, [])
14
15 ids
16 |> Enum.drop(skip)
17 |> Enum.take(per_page)
18 |> Enum.map(&story/1)
19 end
20
21 def story(id) do
22 EslHn.Cache.get(EslHn, id)
23 end
24
25 def broadcast_new(stories) do
26 Phoenix.PubSub.broadcast(EslHn.PubSub, "hn:new", {:new_stories, stories})
27 end
28
29 def subscribe_new do
30 Phoenix.PubSub.subscribe(EslHn.PubSub, "hn:new")
31 end
32end