Add sorting optoins to scrobble rules page

This commit is contained in:
Claudio Ortolina
2026-03-16 08:03:47 +00:00
parent 6d6cf21047
commit 3fb6c93d9d
4 changed files with 59 additions and 3 deletions
+11 -1
View File
@@ -15,6 +15,7 @@ defmodule MusicLibrary.ScrobbleRules do
type: atom(),
enabled: boolean(),
query: String.t(),
order: :inserted_at | :alphabetical,
offset: non_neg_integer(),
limit: non_neg_integer()
]
@@ -22,7 +23,8 @@ defmodule MusicLibrary.ScrobbleRules do
@spec list_scrobble_rules(list_opts()) :: [ScrobbleRule.t()]
def list_scrobble_rules(opts \\ []) do
query =
from(r in ScrobbleRule, order_by: [desc: r.inserted_at])
from(r in ScrobbleRule)
|> order_scrobble_rules(Keyword.get(opts, :order, :inserted_at))
|> filter_scrobble_rules(opts)
query =
@@ -494,6 +496,14 @@ defmodule MusicLibrary.ScrobbleRules do
end
end
defp order_scrobble_rules(query, :alphabetical) do
from r in query, order_by: [asc: r.match_value]
end
defp order_scrobble_rules(query, _inserted_at) do
from r in query, order_by: [desc: r.inserted_at]
end
# column and json_path are hardcoded string literals from internal callers,
# never user input. All user-derived values use parameterized ? placeholders.
# sobelow_skip ["SQL.Query"]