2019-12-20 13:04:34 +01:00
|
|
|
defmodule Mobilizon.Admin.Setting do
|
|
|
|
@moduledoc """
|
|
|
|
A Key-Value settings table for basic settings
|
|
|
|
"""
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
|
|
|
|
@required_attrs [:group, :name]
|
|
|
|
@optional_attrs [:value]
|
|
|
|
@attrs @required_attrs ++ @optional_attrs
|
|
|
|
|
2021-09-24 16:46:42 +02:00
|
|
|
@type t :: %{
|
|
|
|
group: String.t(),
|
|
|
|
name: String.t(),
|
|
|
|
value: String.t()
|
|
|
|
}
|
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
schema "admin_settings" do
|
|
|
|
field(:group, :string)
|
|
|
|
field(:name, :string)
|
|
|
|
field(:value, :string)
|
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
|
2019-12-20 13:04:34 +01:00
|
|
|
def changeset(setting, attrs) do
|
|
|
|
setting
|
|
|
|
|> cast(attrs, @attrs)
|
|
|
|
|> validate_required(@required_attrs)
|
|
|
|
|> unique_constraint(:group, name: :admin_settings_group_name_index)
|
|
|
|
end
|
|
|
|
end
|