diff --git a/lib/app/ctx.ex b/lib/app/ctx.ex index f9fab09..3e7436d 100644 --- a/lib/app/ctx.ex +++ b/lib/app/ctx.ex @@ -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. diff --git a/lib/app_web/controllers/todo_controller.ex b/lib/app_web/controllers/todo_controller.ex index 067a0ea..05b216b 100644 --- a/lib/app_web/controllers/todo_controller.ex +++ b/lib/app_web/controllers/todo_controller.ex @@ -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