Add user setting to provide location and show events near location on

homepage

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-02-12 18:19:49 +01:00
parent 7d8399f4c8
commit b1cc3868a6
27 changed files with 538 additions and 112 deletions

View File

@@ -14,7 +14,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Address do
@spec search(map, map, map) :: {:ok, [Address.t()]}
def search(
_parent,
%{query: query, locale: locale, page: _page, limit: _limit},
%{query: query, locale: locale, page: _page, limit: _limit} = args,
%{context: %{ip: ip}}
) do
geolix = Geolix.lookup(ip)
@@ -25,7 +25,12 @@ defmodule Mobilizon.GraphQL.Resolvers.Address do
_ -> nil
end
addresses = Geospatial.service().search(query, lang: locale, country_code: country_code)
addresses =
Geospatial.service().search(query,
lang: locale,
country_code: country_code,
type: Map.get(args, :type)
)
{:ok, addresses}
end

View File

@@ -56,6 +56,15 @@ defmodule Mobilizon.GraphQL.Schema.AddressType do
field(:origin_id, :string, description: "The address's original ID from the provider")
end
@desc """
A list of possible values for the type option to search an address.
Results may vary depending on the geocoding provider.
"""
enum :address_search_type do
value(:administrative, description: "Administrative results (cities, regions,...)")
end
object :address_queries do
@desc "Search for an address"
field :search_address, type: list_of(:address) do
@@ -73,6 +82,8 @@ defmodule Mobilizon.GraphQL.Schema.AddressType do
arg(:limit, :integer, default_value: 10, description: "The limit of search results per page")
arg(:type, :address_search_type, description: "Filter by type of results")
resolve(&Address.search/3)
end

View File

@@ -101,7 +101,7 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
# field(:sessions, list_of(:session))
field(:updated_at, :datetime, description: "When the event was last updated")
field(:created_at, :datetime, description: "When the event was created")
field(:inserted_at, :datetime, description: "When the event was created")
field(:options, :event_options, description: "The event options")
end

View File

@@ -177,6 +177,10 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
description:
"When does the user receives a notification about a new pending membership in one of the group they're admin for"
)
field(:location, :location,
description: "The user's preferred location, where they want to be suggested events"
)
end
@desc "The list of values the for pending notification settings"
@@ -199,6 +203,25 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
)
end
object :location do
field(:range, :integer, description: "The range in kilometers the user wants to see events")
field(:geohash, :string, description: "A geohash representing the user's preferred location")
field(:name, :string, description: "A string describing the user's preferred location")
end
@desc """
The set of parameters needed to input a location
"""
input_object :location_input do
field(:range, :integer, description: "The range in kilometers the user wants to see events")
field(:geohash, :string, description: "A geohash representing the user's preferred location")
field(:name, :string, description: "A string describing the user's preferred location")
end
object :user_queries do
@desc "Get an user"
field :user, :user do
@@ -343,6 +366,10 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
"When does the user receives a notification about a new pending membership in one of the group they're admin for"
)
arg(:location, :location_input,
description: "A geohash of the user's preferred location, where they want to see events"
)
resolve(&User.set_user_setting/3)
end