Add adresses

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-01-17 11:39:01 +01:00
parent bfcdc38076
commit 07382d6aca
19 changed files with 551 additions and 42 deletions

View File

@@ -0,0 +1,40 @@
defmodule EventosWeb.AddressView do
@moduledoc """
View for addresses
"""
use EventosWeb, :view
alias EventosWeb.AddressView
def render("index.json", %{addresses: addresses}) do
%{data: render_many(addresses, AddressView, "address.json")}
end
def render("show.json", %{address: address}) do
%{data: render_one(address, AddressView, "address.json")}
end
def render("address.json", %{address: address}) do
%{id: address.id,
description: address.description,
floor: address.floor,
addressCountry: address.addressCountry,
addressLocality: address.addressLocality,
addressRegion: address.addressRegion,
postalCode: address.postalCode,
streetAddress: address.streetAddress,
geom: render_one(address.geom, AddressView, "geom.json")
}
end
def render("geom.json", %{address: %Geo.Point{} = point}) do
[lat, lon] = Tuple.to_list(point.coordinates)
%{
type: "point",
data: %{
"latitude": lat,
"longitude": lon,
}
}
end
end

View File

@@ -3,7 +3,7 @@ defmodule EventosWeb.EventView do
View for Events
"""
use EventosWeb, :view
alias EventosWeb.{EventView, AccountView, GroupView}
alias EventosWeb.{EventView, AccountView, GroupView, AddressView}
def render("index.json", %{events: events}) do
%{data: render_many(events, EventView, "event_simple.json")}
@@ -35,6 +35,7 @@ defmodule EventosWeb.EventView do
organizer: render_one(event.organizer_account, AccountView, "acccount_basic.json"),
group: render_one(event.organizer_group, GroupView, "group_basic.json"),
participants: render_many(event.participants, AccountView, "show_basic.json"),
address: render_one(event.address, AddressView, "address.json"),
}
end
end