diff --git a/lib/cannery/ammo.ex b/lib/cannery/ammo.ex index 3927ac4..3cbc60f 100644 --- a/lib/cannery/ammo.ex +++ b/lib/cannery/ammo.ex @@ -38,16 +38,16 @@ defmodule Cannery.Ammo do where: t.user_id == ^user_id, preload: ^@type_preloads ) - |> list_types_filter_class(Keyword.get(opts, :class, :all)) - |> list_types_filter_search(Keyword.get(opts, :search)) + |> list_types_class(Keyword.get(opts, :class, :all)) + |> list_types_search(Keyword.get(opts, :search)) |> Repo.all() end - @spec list_types_filter_search(Queryable.t(), search :: String.t() | nil) :: Queryable.t() - defp list_types_filter_search(query, search) when search in ["", nil], + @spec list_types_search(Queryable.t(), search :: String.t() | nil) :: Queryable.t() + defp list_types_search(query, search) when search in ["", nil], do: query |> order_by([t: t], t.name) - defp list_types_filter_search(query, search) when search |> is_binary() do + defp list_types_search(query, search) when search |> is_binary() do trimmed_search = String.trim(search) query @@ -72,17 +72,11 @@ defmodule Cannery.Ammo do ) end - @spec list_types_filter_class(Queryable.t(), Type.class() | :all) :: Queryable.t() - defp list_types_filter_class(query, :rifle), - do: query |> where([t: t], t.class == :rifle) + @spec list_types_class(Queryable.t(), Type.class() | :all) :: Queryable.t() + defp list_types_class(query, class) when class in [:rifle, :pistol, :shotgun], + do: query |> where([t: t], t.class == ^class) - defp list_types_filter_class(query, :pistol), - do: query |> where([t: t], t.class == :pistol) - - defp list_types_filter_class(query, :shotgun), - do: query |> where([t: t], t.class == :shotgun) - - defp list_types_filter_class(query, _all), do: query + defp list_types_class(query, _all), do: query @doc """ Returns a count of types. @@ -229,7 +223,9 @@ defmodule Cannery.Ammo do defp get_round_count_container_id(query, _nil), do: query @type get_grouped_round_count_option :: - {:types, [Type.t()] | nil} | {:containers, [Container.t()] | nil} | {:group_by, atom()} + {:types, [Type.t()] | nil} + | {:containers, [Container.t()] | nil} + | {:group_by, atom()} @type get_grouped_round_count_options :: [get_grouped_round_count_option()] @doc """ @@ -528,14 +524,8 @@ defmodule Cannery.Ammo do end @spec list_packs_class(Queryable.t(), Type.class() | :all) :: Queryable.t() - defp list_packs_class(query, :rifle), - do: query |> where([t: t], t.class == :rifle) - - defp list_packs_class(query, :pistol), - do: query |> where([t: t], t.class == :pistol) - - defp list_packs_class(query, :shotgun), - do: query |> where([t: t], t.class == :shotgun) + defp list_packs_class(query, class) when class in [:rifle, :pistol, :shotgun], + do: query |> where([t: t], t.class == ^class) defp list_packs_class(query, _all), do: query diff --git a/priv/gettext/de/LC_MESSAGES/errors.po b/priv/gettext/de/LC_MESSAGES/errors.po index bc7ef84..a79574e 100644 --- a/priv/gettext/de/LC_MESSAGES/errors.po +++ b/priv/gettext/de/LC_MESSAGES/errors.po @@ -170,7 +170,7 @@ msgstr "" "Ungültige Nummer an Kopien. Muss zwischen 1 and %{max} liegen. War " "%{multiplier}" -#: lib/cannery/ammo.ex:984 +#: lib/cannery/ammo.ex:974 #, elixir-autogen, elixir-format msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/errors.po b/priv/gettext/en/LC_MESSAGES/errors.po index 5d4b9bf..da617a7 100644 --- a/priv/gettext/en/LC_MESSAGES/errors.po +++ b/priv/gettext/en/LC_MESSAGES/errors.po @@ -153,7 +153,7 @@ msgstr "" msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" msgstr "" -#: lib/cannery/ammo.ex:984 +#: lib/cannery/ammo.ex:974 #, elixir-autogen, elixir-format msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot index 8154b42..df62aff 100644 --- a/priv/gettext/errors.pot +++ b/priv/gettext/errors.pot @@ -152,7 +152,7 @@ msgstr "" msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" msgstr "" -#: lib/cannery/ammo.ex:984 +#: lib/cannery/ammo.ex:974 #, elixir-autogen, elixir-format msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/es/LC_MESSAGES/errors.po b/priv/gettext/es/LC_MESSAGES/errors.po index 522ddc0..f6fcac5 100644 --- a/priv/gettext/es/LC_MESSAGES/errors.po +++ b/priv/gettext/es/LC_MESSAGES/errors.po @@ -168,7 +168,7 @@ msgstr "No se ha podido procesar el número de copias" msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" msgstr "Número inválido de copias, debe ser entre 1 y %{max}. Fue %{multiplier" -#: lib/cannery/ammo.ex:984 +#: lib/cannery/ammo.ex:974 #, elixir-autogen, elixir-format msgid "Invalid multiplier" msgstr "Multiplicador inválido" diff --git a/priv/gettext/fr/LC_MESSAGES/errors.po b/priv/gettext/fr/LC_MESSAGES/errors.po index 8fe50eb..1211ca8 100644 --- a/priv/gettext/fr/LC_MESSAGES/errors.po +++ b/priv/gettext/fr/LC_MESSAGES/errors.po @@ -169,7 +169,7 @@ msgstr "Impossible d'analyser le nombre de copies" msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}" -#: lib/cannery/ammo.ex:984 +#: lib/cannery/ammo.ex:974 #, elixir-autogen, elixir-format msgid "Invalid multiplier" msgstr "Multiplicateur invalide" diff --git a/priv/gettext/ga/LC_MESSAGES/errors.po b/priv/gettext/ga/LC_MESSAGES/errors.po index 7959163..b684d53 100644 --- a/priv/gettext/ga/LC_MESSAGES/errors.po +++ b/priv/gettext/ga/LC_MESSAGES/errors.po @@ -168,7 +168,7 @@ msgstr "" msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}" msgstr "" -#: lib/cannery/ammo.ex:984 +#: lib/cannery/ammo.ex:974 #, elixir-autogen, elixir-format msgid "Invalid multiplier" msgstr ""