Make List report returns a paginated list

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-05-12 18:16:30 +02:00
parent 74778925e0
commit 8c53ea442f
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 9 additions and 5 deletions

View file

@ -30,6 +30,11 @@ defmodule Mobilizon.GraphQL.Schema.ReportType do
field(:updated_at, :datetime, description: "When the report was updated") field(:updated_at, :datetime, description: "When the report was updated")
end end
object :paginated_report_list do
field(:elements, list_of(:report), description: "A list of reports")
field(:total, :integer, description: "The total number of reports in the list")
end
@desc "A report note object" @desc "A report note object"
object :report_note do object :report_note do
interfaces([:action_log_object]) interfaces([:action_log_object])
@ -54,10 +59,10 @@ defmodule Mobilizon.GraphQL.Schema.ReportType do
object :report_queries do object :report_queries do
@desc "Get all reports" @desc "Get all reports"
field :reports, list_of(:report) do field :reports, :paginated_report_list do
arg(:page, :integer, arg(:page, :integer,
default_value: 1, default_value: 1,
description: "The page in the reports participations list" description: "The page in the report list"
) )
arg(:limit, :integer, default_value: 10, description: "The limit of reports per page") arg(:limit, :integer, default_value: 10, description: "The limit of reports per page")

View file

@ -76,7 +76,7 @@ defmodule Mobilizon.Reports do
@doc """ @doc """
Returns the list of reports. Returns the list of reports.
""" """
@spec list_reports(integer | nil, integer | nil, atom, atom, ReportStatus) :: [Report.t()] @spec list_reports(integer | nil, integer | nil, atom, atom, ReportStatus) :: Page.t()
def list_reports( def list_reports(
page \\ nil, page \\ nil,
limit \\ nil, limit \\ nil,
@ -86,9 +86,8 @@ defmodule Mobilizon.Reports do
) do ) do
status status
|> list_reports_query() |> list_reports_query()
|> Page.paginate(page, limit)
|> sort(sort, direction) |> sort(sort, direction)
|> Repo.all() |> Page.build_page(page, limit)
end end
@doc """ @doc """