Fix some warnings
Signed-off-by: Thomas Citharel <tcit@tcit.fr> fix error Signed-off-by: Thomas Citharel <tcit@tcit.fr> Fix tests and warnings Move process_geom/2 to addresses where it belongs Create a special error view for invalid requests Signed-off-by: Thomas Citharel <tcit@tcit.fr> credo fix Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -8,6 +8,10 @@ defmodule Eventos.Addresses do
|
||||
|
||||
alias Eventos.Addresses.Address
|
||||
|
||||
import Logger
|
||||
|
||||
@geom_types [:point]
|
||||
|
||||
@doc """
|
||||
Returns the list of addresses.
|
||||
|
||||
@@ -101,4 +105,36 @@ defmodule Eventos.Addresses do
|
||||
def change_address(%Address{} = address) do
|
||||
Address.changeset(address, %{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Processes raw geo data informations and return a `Geo` geometry which can be one of `Geo.Point`.
|
||||
"""
|
||||
def process_geom(%{"type" => type_input, "data" => data}) do
|
||||
type =
|
||||
if !is_atom(type_input) && type_input != nil do
|
||||
try do
|
||||
String.to_existing_atom(type_input)
|
||||
rescue
|
||||
e in ArgumentError ->
|
||||
Logger.error("#{type_input} is not an existing atom : #{inspect e}")
|
||||
nil
|
||||
end
|
||||
else
|
||||
type_input
|
||||
end
|
||||
|
||||
if Enum.member?(@geom_types, type) do
|
||||
case type do
|
||||
:point ->
|
||||
{:ok, %Geo.Point{coordinates: {data["latitude"], data["longitude"]}, srid: 4326}}
|
||||
end
|
||||
else
|
||||
{:error, nil}
|
||||
end
|
||||
end
|
||||
|
||||
@doc false
|
||||
def process_geom(nil) do
|
||||
{:error, nil}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user