Browse Source

feat: order lists by inserted_at

main
Inhji Y. 3 months ago
parent
commit
c3525a1e83
  1. 18
      lib/mirage/lists.ex

18
lib/mirage/lists.ex

@ -8,7 +8,10 @@ defmodule Mirage.Lists do
alias Mirage.Lists.List
@list_preloads [notes: [:links, :topics, :backlinks, :list]]
def list_preloads() do
note_query = from n in Mirage.Notes.Note, order_by: [desc: n.inserted_at]
[notes: {note_query, [:links, :topics, :backlinks, :list]}]
end
@doc """
Returns the list of lists.
@ -20,8 +23,9 @@ defmodule Mirage.Lists do
"""
def list_lists do
Repo.all(List)
|> Repo.preload(@list_preloads)
List
|> Repo.all()
|> preload_list()
end
@doc """
@ -38,11 +42,13 @@ defmodule Mirage.Lists do
** (Ecto.NoResultsError)
"""
def get_list!(id), do: Repo.get!(List, id) |> Repo.preload(@list_preloads)
def get_list!(id), do: Repo.get!(List, id) |> preload_list()
def get_list_by_name(name), do: Repo.get_by(List, name: name) |> Repo.preload(@list_preloads)
def get_list_by_name(name), do: Repo.get_by(List, name: name) |> preload_list()
def preload_list(list), do: Repo.preload(list, @list_preloads)
def preload_list(list_or_lists) do
Repo.preload(list_or_lists, list_preloads())
end
@doc """
Creates a list.

Loading…
Cancel
Save