Add pagination to AdminAPI.AnnouncementController.index
This commit is contained in:
parent
11a1996bf5
commit
eb1a29640f
4 changed files with 78 additions and 2 deletions
|
|
@ -16,8 +16,13 @@ defmodule Pleroma.Web.AdminAPI.AnnouncementController do
|
|||
|
||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.AnnouncementOperation
|
||||
|
||||
def index(conn, _params) do
|
||||
announcements = Announcement.list_all()
|
||||
defp default_limit, do: 20
|
||||
|
||||
def index(conn, params) do
|
||||
limit = Map.get(params, :limit, default_limit())
|
||||
offset = Map.get(params, :offset, 0)
|
||||
|
||||
announcements = Announcement.list_paginated(%{limit: limit, offset: offset})
|
||||
|
||||
render(conn, "index.json", announcements: announcements)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,8 +21,24 @@ defmodule Pleroma.Web.ApiSpec.Admin.AnnouncementOperation do
|
|||
summary: "Retrieve a list of announcements",
|
||||
operationId: "AdminAPI.AnnouncementController.index",
|
||||
security: [%{"oAuth" => ["admin:read"]}],
|
||||
parameters: [
|
||||
Operation.parameter(
|
||||
:limit,
|
||||
:query,
|
||||
%Schema{type: :integer, minimum: 1},
|
||||
"the maximum number of announcements to return"
|
||||
),
|
||||
Operation.parameter(
|
||||
:offset,
|
||||
:query,
|
||||
%Schema{type: :integer, minimum: 0},
|
||||
"the offset of the first announcement to return"
|
||||
)
|
||||
| admin_api_params()
|
||||
],
|
||||
responses: %{
|
||||
200 => Operation.response("Response", "application/json", list_of_announcements()),
|
||||
400 => Operation.response("Forbidden", "application/json", ApiError),
|
||||
403 => Operation.response("Forbidden", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue