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:
Thomas Citharel
2018-01-21 19:43:16 +01:00
parent adf1888fc7
commit 22093b8ca4
8 changed files with 77 additions and 34 deletions

View File

@@ -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