paginate follow requests (#460)
[akkoma] / lib / pleroma / web / api_spec / operations / follow_request_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.FollowRequestOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Account
9 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
10
11 def open_api_operation(action) do
12 operation = String.to_existing_atom("#{action}_operation")
13 apply(__MODULE__, operation, [])
14 end
15
16 def index_operation do
17 %Operation{
18 tags: ["Follow requests"],
19 summary: "Retrieve follow requests",
20 security: [%{"oAuth" => ["read:follows", "follow"]}],
21 operationId: "FollowRequestController.index",
22 parameters: pagination_params(),
23 responses: %{
24 200 =>
25 Operation.response("Array of Account", "application/json", %Schema{
26 type: :array,
27 items: Account,
28 example: [Account.schema().example]
29 })
30 }
31 }
32 end
33
34 def authorize_operation do
35 %Operation{
36 tags: ["Follow requests"],
37 summary: "Accept follow request",
38 operationId: "FollowRequestController.authorize",
39 parameters: [id_param()],
40 security: [%{"oAuth" => ["follow", "write:follows"]}],
41 responses: %{
42 200 => Operation.response("Relationship", "application/json", AccountRelationship)
43 }
44 }
45 end
46
47 def reject_operation do
48 %Operation{
49 tags: ["Follow requests"],
50 summary: "Reject follow request",
51 operationId: "FollowRequestController.reject",
52 parameters: [id_param()],
53 security: [%{"oAuth" => ["follow", "write:follows"]}],
54 responses: %{
55 200 => Operation.response("Relationship", "application/json", AccountRelationship)
56 }
57 }
58 end
59
60 defp id_param do
61 Operation.parameter(:id, :path, :string, "Conversation ID",
62 example: "123",
63 required: true
64 )
65 end
66
67 defp pagination_params do
68 [
69 Operation.parameter(:max_id, :query, :string, "Return items older than this ID"),
70 Operation.parameter(
71 :since_id,
72 :query,
73 :string,
74 "Return the oldest items newer than this ID"
75 ),
76 Operation.parameter(
77 :limit,
78 :query,
79 %Schema{type: :integer, default: 20},
80 "Maximum number of items to return. Will be ignored if it's more than 40"
81 )
82 ]
83 end
84 end