2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Resolvers.Search do
|
2019-02-21 18:11:49 +01:00
|
|
|
@moduledoc """
|
|
|
|
Handles the event-related GraphQL calls
|
|
|
|
"""
|
2021-09-28 19:40:37 +02:00
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Events.Event
|
2020-01-26 21:11:16 +01:00
|
|
|
alias Mobilizon.GraphQL.API.Search
|
2021-09-28 19:40:37 +02:00
|
|
|
alias Mobilizon.Storage.Page
|
2019-02-21 18:11:49 +01:00
|
|
|
|
|
|
|
@doc """
|
2019-04-12 15:04:32 +02:00
|
|
|
Search persons
|
2019-02-21 18:11:49 +01:00
|
|
|
"""
|
2021-09-28 19:40:37 +02:00
|
|
|
@spec search_persons(any(), map(), Absinthe.Resolution.t()) ::
|
|
|
|
{:ok, Page.t(Actor.t())} | {:error, String.t()}
|
2020-08-05 16:44:08 +02:00
|
|
|
def search_persons(_parent, %{page: page, limit: limit} = args, _resolution) do
|
2021-05-02 19:27:34 +02:00
|
|
|
Search.search_actors(Map.put(args, :minimum_visibility, :private), page, limit, :Person)
|
2019-04-12 15:04:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Search groups
|
|
|
|
"""
|
2021-09-28 19:40:37 +02:00
|
|
|
@spec search_groups(any(), map(), Absinthe.Resolution.t()) ::
|
|
|
|
{:ok, Page.t(Actor.t())} | {:error, String.t()}
|
2021-11-06 10:09:54 +01:00
|
|
|
def search_groups(
|
|
|
|
_parent,
|
|
|
|
%{page: page, limit: limit} = args,
|
|
|
|
%{context: context} = _resolution
|
|
|
|
) do
|
|
|
|
current_actor = Map.get(context, :current_actor, nil)
|
|
|
|
current_actor_id = if current_actor, do: current_actor.id, else: nil
|
|
|
|
args = Map.put(args, :current_actor_id, current_actor_id)
|
2020-08-05 16:44:08 +02:00
|
|
|
Search.search_actors(args, page, limit, :Group)
|
2019-04-12 15:04:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Search events
|
|
|
|
"""
|
2021-09-28 19:40:37 +02:00
|
|
|
@spec search_events(any(), map(), Absinthe.Resolution.t()) ::
|
|
|
|
{:ok, Page.t(Event.t())} | {:error, String.t()}
|
2020-07-31 17:52:26 +02:00
|
|
|
def search_events(_parent, %{page: page, limit: limit} = args, _resolution) do
|
|
|
|
Search.search_events(args, page, limit)
|
2019-02-21 18:11:49 +01:00
|
|
|
end
|
2020-11-06 11:34:32 +01:00
|
|
|
|
2021-09-28 19:40:37 +02:00
|
|
|
@spec interact(any(), map(), Absinthe.Resolution.t()) :: {:ok, struct} | {:error, :not_found}
|
2020-11-06 11:34:32 +01:00
|
|
|
def interact(_parent, %{uri: uri}, _resolution) do
|
|
|
|
Search.interact(uri)
|
|
|
|
end
|
2019-02-21 18:11:49 +01:00
|
|
|
end
|