Skip to content

Commit

Permalink
Featured articles
Browse files Browse the repository at this point in the history
  • Loading branch information
msp committed Dec 18, 2019
1 parent cd9bf2e commit 84a760b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Visit [`localhost:4000`](http://localhost:4000) in your browser.
$ mix test.watch

# start the server
$ iex -S mix phoenix.server
$ iex -S mix phx.server

```

Expand Down
16 changes: 10 additions & 6 deletions lib/cenatus_ltd_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ defmodule CenatusLtdWeb.PageController do
plug(:load_periodic)

def home(conn, _params) do
articles =
Repo.all(
from(article in Article,
limit: 2,
order_by: [desc: article.published_at]
articles = get_articles_tagged_by("featured")

if length(articles) == 0 do
articles =
Repo.all(
from(article in Article,
limit: 2,
order_by: [desc: article.published_at]
)
)
)
end

conn
|> put_view(CenatusLtdWeb.SharedView)
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/page_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ defmodule CenatusLtdWeb.PageControllerTest do
use CenatusLtdWeb.ConnCase

test "GET /", %{conn: conn} do
creative_article = insert_article(%{"title" => "creative article"})
technology_article = insert_article(%{"title" => "technology article"})
creative_article = insert_article(%{"title" => "creative article", "tags" => "featured"})
technology_article = insert_article(%{"title" => "technology article", "tags" => "featured"})
production_article = insert_article(%{"title" => "production article"})

conn = get conn, "/"
Expand Down

0 comments on commit 84a760b

Please sign in to comment.