2019-03-04 17:38:30 +00:00
|
|
|
defmodule MobilizonWeb.JsonLD.ObjectView do
|
|
|
|
use MobilizonWeb, :view
|
|
|
|
|
2019-03-05 09:13:19 +00:00
|
|
|
alias Mobilizon.Events.Event
|
2019-03-04 17:38:30 +00:00
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Addresses.Address
|
|
|
|
alias MobilizonWeb.JsonLD.ObjectView
|
2019-05-28 08:51:02 +00:00
|
|
|
alias MobilizonWeb.MediaProxy
|
2019-03-04 17:38:30 +00:00
|
|
|
|
|
|
|
def render("event.json", %{event: %Event{} = event}) do
|
|
|
|
# TODO: event.description is actually markdown!
|
2019-05-22 12:12:11 +00:00
|
|
|
|
2019-03-04 17:38:30 +00:00
|
|
|
json_ld = %{
|
|
|
|
"@context" => "https://schema.org",
|
|
|
|
"@type" => "Event",
|
|
|
|
"name" => event.title,
|
|
|
|
"description" => event.description,
|
|
|
|
"performer" => %{
|
|
|
|
"@type" =>
|
|
|
|
if(event.organizer_actor.type == :Group, do: "PerformingGroup", else: "Person"),
|
|
|
|
"name" => Actor.display_name(event.organizer_actor)
|
|
|
|
},
|
|
|
|
"location" => render_one(event.physical_address, ObjectView, "place.json", as: :address)
|
|
|
|
}
|
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
json_ld =
|
|
|
|
if event.picture do
|
|
|
|
Map.put(json_ld, "image", [
|
2019-05-28 08:51:02 +00:00
|
|
|
event.picture.file.url |> MediaProxy.url()
|
2019-05-22 12:12:11 +00:00
|
|
|
])
|
|
|
|
else
|
|
|
|
json_ld
|
|
|
|
end
|
|
|
|
|
2019-03-04 17:38:30 +00:00
|
|
|
json_ld =
|
|
|
|
if event.begins_on,
|
|
|
|
do: Map.put(json_ld, "startDate", DateTime.to_iso8601(event.begins_on)),
|
|
|
|
else: json_ld
|
|
|
|
|
|
|
|
json_ld =
|
|
|
|
if event.ends_on,
|
|
|
|
do: Map.put(json_ld, "endDate", DateTime.to_iso8601(event.ends_on)),
|
|
|
|
else: json_ld
|
|
|
|
|
|
|
|
json_ld
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("place.json", %{address: %Address{} = address}) do
|
|
|
|
%{
|
|
|
|
"@type" => "Place",
|
|
|
|
"name" => address.description,
|
|
|
|
"address" => %{
|
|
|
|
"@type" => "PostalAddress",
|
2019-03-22 14:51:23 +00:00
|
|
|
"streetAddress" => address.street,
|
|
|
|
"addressLocality" => address.locality,
|
|
|
|
"postalCode" => address.postal_code,
|
|
|
|
"addressRegion" => address.region,
|
|
|
|
"addressCountry" => address.country
|
2019-03-04 17:38:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("place.json", nil), do: %{}
|
|
|
|
end
|