diff --git a/lib/graphql/resolvers/place.ex b/lib/graphql/resolvers/place.ex new file mode 100644 index 000000000..e69de29bb diff --git a/lib/graphql/schema/place.ex b/lib/graphql/schema/place.ex new file mode 100644 index 000000000..805b07f23 --- /dev/null +++ b/lib/graphql/schema/place.ex @@ -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 diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 6960acc98..b26eec510 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -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(