Skip to content

Commit

Permalink
sort list by priority #1
Browse files Browse the repository at this point in the history
  • Loading branch information
RobStallion committed Jun 5, 2019
1 parent 0690934 commit 97648c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/app/ctx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ defmodule App.Ctx do
Repo.all(Todo)
end

def list_todos_by_priority do
query = from t in Todo, select: t, order_by: [asc: t.priority, desc: t.updated_at]
Repo.all(query)
end

@doc """
Gets a single todo.
Expand Down
2 changes: 1 addition & 1 deletion lib/app_web/controllers/todo_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule AppWeb.TodoController do
alias App.Ctx.Todo

def index(conn, _params) do
todos = Ctx.list_todos()
todos = Ctx.list_todos_by_priority()
render(conn, "index.html", todos: todos)
end

Expand Down

0 comments on commit 97648c0

Please sign in to comment.