Add pagination for scrobble rules

This commit is contained in:
Claudio Ortolina
2025-12-14 09:21:13 +03:00
parent b890e5cffe
commit 0df348ae19
6 changed files with 167 additions and 11 deletions
+55
View File
@@ -45,9 +45,64 @@ defmodule MusicLibrary.ScrobbleRules do
where: r.enabled == ^enabled
end
query =
case Keyword.get(opts, :offset) do
nil ->
query
offset ->
from r in query,
offset: ^offset
end
query =
case Keyword.get(opts, :limit) do
nil ->
query
limit ->
from r in query,
limit: ^limit
end
Repo.all(query)
end
@doc """
Returns the count of scrobble_rules.
## Examples
iex> count_scrobble_rules()
42
"""
def count_scrobble_rules(opts \\ []) do
query = from(r in ScrobbleRule)
query =
case Keyword.get(opts, :type) do
nil ->
query
type ->
from r in query,
where: r.type == ^type
end
query =
case Keyword.get(opts, :enabled) do
nil ->
query
enabled ->
from r in query,
where: r.enabled == ^enabled
end
Repo.aggregate(query, :count)
end
@doc """
Gets a single scrobble_rule.