Allow to search events by online status

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-11-06 14:37:45 +01:00
parent 9ac3da618d
commit 69e91e89f5
8 changed files with 232 additions and 75 deletions

View File

@@ -44,6 +44,15 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
end)
end
enum :event_type do
value(:in_person,
description:
"The event will happen in person. It can also be livestreamed, but has a physical address"
)
value(:online, description: "The event will only happen online. It has no physical address")
end
object :search_queries do
@desc "Search persons"
field :search_persons, :persons do
@@ -83,6 +92,7 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
arg(:term, :string, default_value: "")
arg(:tags, :string, description: "A comma-separated string listing the tags")
arg(:location, :string, description: "A geohash for coordinates")
arg(:type, :event_type, description: "Whether the event is online or in person")
arg(:radius, :float,
default_value: 50,

View File

@@ -506,6 +506,7 @@ defmodule Mobilizon.Events do
|> events_for_ends_on(args)
|> events_for_tags(args)
|> events_for_location(args)
|> filter_online(args)
|> filter_draft()
|> filter_local_or_from_followed_instances_events()
|> filter_public_visibility()
@@ -1307,6 +1308,18 @@ defmodule Mobilizon.Events do
defp events_for_location(query, _args), do: query
@spec filter_online(Ecto.Query.t(), map()) :: Ecto.Query.t()
defp filter_online(query, %{type: :online}), do: is_online_fragment(query, true)
defp filter_online(query, %{type: :in_person}), do: is_online_fragment(query, false)
defp filter_online(query, _), do: query
@spec is_online_fragment(Ecto.Query.t(), boolean()) :: Ecto.Query.t()
defp is_online_fragment(query, value) do
where(query, [q], fragment("(?->>'is_online')::bool = ?", q.options, ^value))
end
@spec normalize_search_string(String.t()) :: String.t()
defp normalize_search_string(search_string) do
search_string