Introduce places

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-10-25 18:34:14 +02:00
parent 2c99f8c52d
commit 26e23128c5
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 70 additions and 2 deletions

View File

View File

@ -0,0 +1,47 @@
defmodule Mobilizon.GraphQL.Schema.AddressType do
@moduledoc """
Schema representation for Address
"""
use Absinthe.Schema.Notation
alias Mobilizon.GraphQL.Resolvers.Place
@desc """
An place object
"""
object :place do
field(:geom, :point, description: "The geocoordinates for the point where this place is")
field(:name, :string, description: "The place name")
field(:events, :paginated_event_list,
description: "The list of events on this place",
resolve: &Place.events/3
)
field(:groups, :paginated_group_list,
description: "The list of groups on this place",
resolve: &Place.groups/3
)
end
object :places_queries do
@desc "Get trending places"
field :trending_places, :paginated_place_list do
arg(:query, :string)
arg(:locale, :string,
default_value: "en",
description: "The user's locale. Geocoding backends will make use of this value."
)
arg(:page, :integer,
default_value: 1,
description: "The page in the paginated search results list"
)
arg(:limit, :integer, default_value: 10, description: "The limit of search places per page")
resolve(&Place.search/3)
end
end
end

View File

@ -513,6 +513,20 @@ defmodule Mobilizon.Events do
|> Page.build_page(page, limit, :begins_on)
end
def build_events_for_place(location) do
Event
|> events_for_begins_on(%{})
|> events_for_ends_on(%{})
|> events_for_location(%{
longitude: location.longitude,
latitude: location.latitude,
radius: 10_000
})
|> filter_draft()
|> filter_local_or_from_followed_instances_events()
|> filter_public_visibility()
end
@doc """
Gets a single tag.
"""
@ -1292,8 +1306,15 @@ defmodule Mobilizon.Events do
defp events_for_location(query, %{location: location, radius: radius})
when is_valid_string(location) and not is_nil(radius) do
with {lon, lat} <- Geohax.decode(location),
point <- Geo.WKT.decode!("SRID=4326;POINT(#{lon} #{lat})") do
with {lon, lat} <- Geohax.decode(location) do
events_for_location(query, %{longitude: lon, latitude: lat, radius: radius})
else
_ -> query
end
end
defp events_for_location(query, %{longitude: longitude, latitude: latitude, radius: radius}) do
with point <- Geo.WKT.decode!("SRID=4326;POINT(#{longitude} #{latitude})") do
query
|> join(:inner, [q], a in Address, on: a.id == q.physical_address_id, as: :address)
|> where(