72dc8b5face5d4d23d0bbcdfff3825d355ae4c6e
[anni] / lib / pleroma / web / api_spec / operations / follow_request_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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       responses: %{
23         200 =>
24           Operation.response("Array of Account", "application/json", %Schema{
25             type: :array,
26             items: Account,
27             example: [Account.schema().example]
28           })
29       }
30     }
31   end
32
33   def authorize_operation do
34     %Operation{
35       tags: ["Follow requests"],
36       summary: "Accept follow request",
37       operationId: "FollowRequestController.authorize",
38       parameters: [id_param()],
39       security: [%{"oAuth" => ["follow", "write:follows"]}],
40       responses: %{
41         200 => Operation.response("Relationship", "application/json", AccountRelationship)
42       }
43     }
44   end
45
46   def reject_operation do
47     %Operation{
48       tags: ["Follow requests"],
49       summary: "Reject follow request",
50       operationId: "FollowRequestController.reject",
51       parameters: [id_param()],
52       security: [%{"oAuth" => ["follow", "write:follows"]}],
53       responses: %{
54         200 => Operation.response("Relationship", "application/json", AccountRelationship)
55       }
56     }
57   end
58
59   defp id_param do
60     Operation.parameter(:id, :path, :string, "Conversation ID",
61       example: "123",
62       required: true
63     )
64   end
65 end