@@ -8,6 +8,8 @@ defmodule MusicLibrary.OnlineStoreTemplates do
|
|||||||
alias MusicLibrary.OnlineStoreTemplates.OnlineStoreTemplate
|
alias MusicLibrary.OnlineStoreTemplates.OnlineStoreTemplate
|
||||||
alias MusicLibrary.Repo
|
alias MusicLibrary.Repo
|
||||||
|
|
||||||
|
@pagination Application.compile_env!(:music_library, :pagination)
|
||||||
|
|
||||||
@spec list_enabled_templates() :: [OnlineStoreTemplate.t()]
|
@spec list_enabled_templates() :: [OnlineStoreTemplate.t()]
|
||||||
def list_enabled_templates do
|
def list_enabled_templates do
|
||||||
OnlineStoreTemplate
|
OnlineStoreTemplate
|
||||||
@@ -32,19 +34,13 @@ defmodule MusicLibrary.OnlineStoreTemplates do
|
|||||||
|> order_by([t], fragment("? COLLATE NOCASE ASC", t.name))
|
|> order_by([t], fragment("? COLLATE NOCASE ASC", t.name))
|
||||||
|> filter_templates(opts)
|
|> filter_templates(opts)
|
||||||
|
|
||||||
query =
|
offset = Keyword.get(opts, :offset, 0)
|
||||||
case Keyword.get(opts, :offset) do
|
limit = Keyword.get(opts, :limit, @pagination[:default_page_size])
|
||||||
nil -> query
|
|
||||||
offset -> from(t in query, offset: ^offset)
|
|
||||||
end
|
|
||||||
|
|
||||||
query =
|
query
|
||||||
case Keyword.get(opts, :limit) do
|
|> offset(^offset)
|
||||||
nil -> query
|
|> limit(^limit)
|
||||||
limit -> from(t in query, limit: ^limit)
|
|> Repo.all()
|
||||||
end
|
|
||||||
|
|
||||||
Repo.all(query)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec count_templates(list_opts()) :: non_neg_integer()
|
@spec count_templates(list_opts()) :: non_neg_integer()
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ defmodule MusicLibrary.ScrobbleRules do
|
|||||||
alias MusicLibrary.Repo
|
alias MusicLibrary.Repo
|
||||||
alias MusicLibrary.ScrobbleRules.ScrobbleRule
|
alias MusicLibrary.ScrobbleRules.ScrobbleRule
|
||||||
|
|
||||||
|
@pagination Application.compile_env!(:music_library, :pagination)
|
||||||
|
|
||||||
@type list_opts :: [
|
@type list_opts :: [
|
||||||
type: atom(),
|
type: atom(),
|
||||||
enabled: boolean(),
|
enabled: boolean(),
|
||||||
@@ -27,27 +29,13 @@ defmodule MusicLibrary.ScrobbleRules do
|
|||||||
|> order_scrobble_rules(Keyword.get(opts, :order, :inserted_at))
|
|> order_scrobble_rules(Keyword.get(opts, :order, :inserted_at))
|
||||||
|> filter_scrobble_rules(opts)
|
|> filter_scrobble_rules(opts)
|
||||||
|
|
||||||
query =
|
offset = Keyword.get(opts, :offset, 0)
|
||||||
case Keyword.get(opts, :offset) do
|
limit = Keyword.get(opts, :limit, @pagination[:default_page_size])
|
||||||
nil ->
|
|
||||||
query
|
|
||||||
|
|
||||||
offset ->
|
query
|
||||||
from r in query,
|
|> offset(^offset)
|
||||||
offset: ^offset
|
|> limit(^limit)
|
||||||
end
|
|> Repo.all()
|
||||||
|
|
||||||
query =
|
|
||||||
case Keyword.get(opts, :limit) do
|
|
||||||
nil ->
|
|
||||||
query
|
|
||||||
|
|
||||||
limit ->
|
|
||||||
from r in query,
|
|
||||||
limit: ^limit
|
|
||||||
end
|
|
||||||
|
|
||||||
Repo.all(query)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec count_scrobble_rules(list_opts()) :: non_neg_integer()
|
@spec count_scrobble_rules(list_opts()) :: non_neg_integer()
|
||||||
|
|||||||
Reference in New Issue
Block a user