spatial_thing.ex (1778B)
1 # Zenflows is designed to implement the Valueflows vocabulary, 2 # written and maintained by srfsh <info@dyne.org>. 3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>. 4 # 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU Affero General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU Affero General Public License for more details. 14 # 15 # You should have received a copy of the GNU Affero General Public License 16 # along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18 defmodule Zenflows.VF.SpatialThing do 19 @moduledoc """ 20 A physical mappable location. 21 """ 22 23 use Zenflows.DB.Schema 24 25 alias Ecto.Changeset 26 alias Zenflows.DB.{Schema, Validate} 27 28 @type t() :: %__MODULE__{ 29 id: String.t(), 30 name: String.t(), 31 mappable_address: String.t() | nil, 32 lat: Decimal.t() | nil, 33 long: Decimal.t() | nil, 34 alt: Decimal.t() | nil, 35 note: String.t() | nil, 36 } 37 38 @reqr [:name] 39 @cast @reqr ++ ~w[mappable_address lat long alt note]a 40 41 schema "vf_spatial_thing" do 42 field :name, :string 43 field :mappable_address, :string 44 field :lat, :decimal 45 field :long, :decimal 46 field :alt, :decimal 47 field :note, :string 48 timestamps() 49 end 50 51 @doc false 52 @spec changeset(Schema.t(), Schema.params()) :: Changeset.t() 53 def changeset(schema \\ %__MODULE__{}, params) do 54 schema 55 |> Changeset.cast(params, @cast) 56 |> Changeset.validate_required(@reqr) 57 |> Validate.name(:name) 58 |> Validate.note(:note) 59 |> Validate.note(:mappable_address) 60 end 61 end