Add pagination to events, groups, partipants to an event and categories

lists
This commit is contained in:
Chocobozzz
2018-12-14 11:23:36 +01:00
parent 72dbc8c261
commit 48eb72cd4c
11 changed files with 92 additions and 72 deletions

View File

@@ -2,9 +2,9 @@ defmodule MobilizonWeb.Resolvers.Category do
require Logger
alias Mobilizon.Actors.User
def list_categories(_parent, _args, _resolution) do
def list_categories(_parent, %{page: page, limit: limit}, _resolution) do
categories =
Mobilizon.Events.list_categories()
Mobilizon.Events.list_categories(page, limit)
|> Enum.map(fn category ->
urls = MobilizonWeb.Uploaders.Category.urls({category.picture, category})
Map.put(category, :picture, %{url: urls.original, url_thumbnail: urls.thumb})

View File

@@ -2,8 +2,8 @@ defmodule MobilizonWeb.Resolvers.Event do
alias Mobilizon.Service.ActivityPub
alias Mobilizon.Actors
def list_events(_parent, _args, _resolution) do
{:ok, Mobilizon.Events.list_events()}
def list_events(_parent, %{page: page, limit: limit}, _resolution) do
{:ok, Mobilizon.Events.list_events(page, limit)}
end
def find_event(_parent, %{uuid: uuid}, _resolution) do
@@ -26,8 +26,8 @@ defmodule MobilizonWeb.Resolvers.Event do
@doc """
List participants for event (through an event request)
"""
def list_participants_for_event(%{uuid: uuid}, _args, _resolution) do
{:ok, Mobilizon.Events.list_participants_for_event(uuid)}
def list_participants_for_event(%{uuid: uuid}, %{page: page, limit: limit}, _resolution) do
{:ok, Mobilizon.Events.list_participants_for_event(uuid, page, limit)}
end
@doc """

View File

@@ -20,8 +20,8 @@ defmodule MobilizonWeb.Resolvers.Group do
@doc """
Lists all groups
"""
def list_groups(_parent, _args, _resolution) do
{:ok, Actors.list_groups()}
def list_groups(_parent, %{page: page, limit: limit}, _resolution) do
{:ok, Actors.list_groups(page, limit)}
end
@doc """

View File

@@ -322,7 +322,7 @@ defmodule MobilizonWeb.Schema do
end
@desc """
Represents an actor's follower
Represents an actor's follower
"""
object :follower do
field(:target_actor, :actor, description: "What or who the profile follows")
@@ -395,11 +395,15 @@ defmodule MobilizonWeb.Schema do
query do
@desc "Get all events"
field :events, list_of(:event) do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Event.list_events/3)
end
@desc "Get all groups"
field :groups, list_of(:group) do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Group.list_groups/3)
end
@@ -420,6 +424,8 @@ defmodule MobilizonWeb.Schema do
@desc "Get all participants for an event uuid"
field :participants, list_of(:participant) do
arg(:uuid, non_null(:uuid))
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Event.list_participants_for_event/3)
end
@@ -453,6 +459,8 @@ defmodule MobilizonWeb.Schema do
@desc "Get the list of categories"
field :categories, non_null(list_of(:category)) do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Category.list_categories/3)
end
end