[JSON-LD] Only render single location when list has only one element

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-08-23 10:09:10 +02:00
parent 2eee09bf4b
commit bfc936f57c
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -176,6 +176,7 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
[]
|> render_location(event)
|> render_virtual_location(event)
|> maybe_render_single_element()
end
@spec render_location(list(), map()) :: list()
@ -207,6 +208,10 @@ defmodule Mobilizon.Web.JsonLD.ObjectView do
defp render_virtual_location(locations, _), do: locations
@spec maybe_render_single_element(list(map())) :: list(map()) | map()
defp maybe_render_single_element([location]), do: location
defp maybe_render_single_element(locations), do: locations
defp render_address(%{physical_address: %Address{} = address}),
do: render_one(address, ObjectView, "address.json", as: :address)