diff --git a/lib/cannery/ammo.ex b/lib/cannery/ammo.ex index 3c62ab68..0be8e860 100644 --- a/lib/cannery/ammo.ex +++ b/lib/cannery/ammo.ex @@ -141,11 +141,8 @@ defmodule Cannery.Ammo do """ @spec create_ammo_type(attrs :: map(), User.t()) :: {:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.new_ammo_type())} - def create_ammo_type(attrs \\ %{}, %User{id: user_id}) do - %AmmoType{} - |> AmmoType.create_changeset(attrs |> Map.put("user_id", user_id)) - |> Repo.insert() - end + def create_ammo_type(attrs \\ %{}, %User{} = user), + do: %AmmoType{} |> AmmoType.create_changeset(user, attrs) |> Repo.insert() @doc """ Updates a ammo_type. diff --git a/lib/cannery/ammo/ammo_type.ex b/lib/cannery/ammo/ammo_type.ex index d7593f78..c6e5012a 100644 --- a/lib/cannery/ammo/ammo_type.ex +++ b/lib/cannery/ammo/ammo_type.ex @@ -105,10 +105,12 @@ defmodule Cannery.Ammo.AmmoType do ] @doc false - @spec create_changeset(new_ammo_type(), attrs :: map()) :: Changeset.t(new_ammo_type()) - def create_changeset(ammo_type, attrs) do + @spec create_changeset(new_ammo_type(), User.t(), attrs :: map()) :: + Changeset.t(new_ammo_type()) + def create_changeset(ammo_type, %User{id: user_id}, attrs) do ammo_type - |> cast(attrs, [:user_id | changeset_fields()]) + |> change(user_id: user_id) + |> cast(attrs, changeset_fields()) |> validate_required([:name, :user_id]) end diff --git a/priv/gettext/de/LC_MESSAGES/errors.po b/priv/gettext/de/LC_MESSAGES/errors.po index 0289b9b1..c764d283 100644 --- a/priv/gettext/de/LC_MESSAGES/errors.po +++ b/priv/gettext/de/LC_MESSAGES/errors.po @@ -188,7 +188,7 @@ msgstr "" "%{multiplier}" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:404 msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/errors.po b/priv/gettext/en/LC_MESSAGES/errors.po index dfb3bf98..6722c218 100644 --- a/priv/gettext/en/LC_MESSAGES/errors.po +++ b/priv/gettext/en/LC_MESSAGES/errors.po @@ -171,7 +171,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier} msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:404 msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot index e2d2ce8c..bf7fb127 100644 --- a/priv/gettext/errors.pot +++ b/priv/gettext/errors.pot @@ -170,7 +170,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier} msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:404 msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/es/LC_MESSAGES/errors.po b/priv/gettext/es/LC_MESSAGES/errors.po index d1a1f113..f741caae 100644 --- a/priv/gettext/es/LC_MESSAGES/errors.po +++ b/priv/gettext/es/LC_MESSAGES/errors.po @@ -181,7 +181,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier} msgstr "" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:404 msgid "Invalid multiplier" msgstr "" diff --git a/priv/gettext/fr/LC_MESSAGES/errors.po b/priv/gettext/fr/LC_MESSAGES/errors.po index d391effe..d0809bae 100644 --- a/priv/gettext/fr/LC_MESSAGES/errors.po +++ b/priv/gettext/fr/LC_MESSAGES/errors.po @@ -187,7 +187,7 @@ 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}" #, elixir-autogen, elixir-format -#: lib/cannery/ammo.ex:407 +#: lib/cannery/ammo.ex:404 msgid "Invalid multiplier" msgstr ""