2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Resolvers.Tag do
|
2019-02-14 14:19:55 +01:00
|
|
|
@moduledoc """
|
|
|
|
Handles the tag-related GraphQL calls
|
|
|
|
"""
|
2019-07-26 11:30:28 +02:00
|
|
|
alias Mobilizon.Events
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.Events.{Event, Tag}
|
2019-02-14 14:19:55 +01:00
|
|
|
|
|
|
|
def list_tags(_parent, %{page: page, limit: limit}, _resolution) do
|
|
|
|
tags = Mobilizon.Events.list_tags(page, limit)
|
|
|
|
|
|
|
|
{:ok, tags}
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Retrieve the list of tags for an event
|
|
|
|
"""
|
|
|
|
def list_tags_for_event(%Event{id: id}, _args, _resolution) do
|
|
|
|
{:ok, Mobilizon.Events.list_tags_for_event(id)}
|
|
|
|
end
|
|
|
|
|
2019-07-26 11:30:28 +02:00
|
|
|
@doc """
|
|
|
|
Retrieve the list of tags for an event
|
|
|
|
"""
|
|
|
|
def list_tags_for_event(%{url: url}, _args, _resolution) do
|
|
|
|
with %Event{id: event_id} <- Events.get_event_by_url(url) do
|
|
|
|
{:ok, Mobilizon.Events.list_tags_for_event(event_id)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-22 18:07:20 +01:00
|
|
|
# @doc """
|
|
|
|
# Retrieve the list of related tags for a given tag ID
|
|
|
|
# """
|
|
|
|
# def get_related_tags(_parent, %{tag_id: tag_id}, _resolution) do
|
|
|
|
# with %Tag{} = tag <- Mobilizon.Events.get_tag!(tag_id),
|
2019-09-16 02:07:44 +02:00
|
|
|
# tags <- Mobilizon.Events.list_tag_neighbors(tag) do
|
2019-02-22 18:07:20 +01:00
|
|
|
# {:ok, tags}
|
|
|
|
# end
|
|
|
|
# end
|
2019-02-14 14:19:55 +01:00
|
|
|
|
|
|
|
@doc """
|
|
|
|
Retrieve the list of related tags for a parent tag
|
|
|
|
"""
|
|
|
|
def get_related_tags(%Tag{} = tag, _args, _resolution) do
|
2019-09-16 02:07:44 +02:00
|
|
|
with tags <- Mobilizon.Events.list_tag_neighbors(tag) do
|
2019-02-14 14:19:55 +01:00
|
|
|
{:ok, tags}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|