mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-21 23:44:30 +00:00
Introduce places
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
2c99f8c52d
commit
26e23128c5
3 changed files with 70 additions and 2 deletions
0
lib/graphql/resolvers/place.ex
Normal file
0
lib/graphql/resolvers/place.ex
Normal file
47
lib/graphql/schema/place.ex
Normal file
47
lib/graphql/schema/place.ex
Normal 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
|
|
@ -513,6 +513,20 @@ defmodule Mobilizon.Events do
|
||||||
|> Page.build_page(page, limit, :begins_on)
|
|> Page.build_page(page, limit, :begins_on)
|
||||||
end
|
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 """
|
@doc """
|
||||||
Gets a single tag.
|
Gets a single tag.
|
||||||
"""
|
"""
|
||||||
|
@ -1292,8 +1306,15 @@ defmodule Mobilizon.Events do
|
||||||
|
|
||||||
defp events_for_location(query, %{location: location, radius: radius})
|
defp events_for_location(query, %{location: location, radius: radius})
|
||||||
when is_valid_string(location) and not is_nil(radius) do
|
when is_valid_string(location) and not is_nil(radius) do
|
||||||
with {lon, lat} <- Geohax.decode(location),
|
with {lon, lat} <- Geohax.decode(location) do
|
||||||
point <- Geo.WKT.decode!("SRID=4326;POINT(#{lon} #{lat})") 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
|
query
|
||||||
|> join(:inner, [q], a in Address, on: a.id == q.physical_address_id, as: :address)
|
|> join(:inner, [q], a in Address, on: a.id == q.physical_address_id, as: :address)
|
||||||
|> where(
|
|> where(
|
||||||
|
|
Loading…
Reference in a new issue