First
[anni] / lib / pleroma / web / api_spec / operations / scheduled_activity_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.ScheduledActivityOperation do
6   alias OpenApiSpex.Operation
7   alias OpenApiSpex.Schema
8   alias Pleroma.Web.ApiSpec.Schemas.ApiError
9   alias Pleroma.Web.ApiSpec.Schemas.FlakeID
10   alias Pleroma.Web.ApiSpec.Schemas.ScheduledStatus
11
12   import Pleroma.Web.ApiSpec.Helpers
13
14   def open_api_operation(action) do
15     operation = String.to_existing_atom("#{action}_operation")
16     apply(__MODULE__, operation, [])
17   end
18
19   def index_operation do
20     %Operation{
21       tags: ["Scheduled statuses"],
22       summary: "View scheduled statuses",
23       security: [%{"oAuth" => ["read:statuses"]}],
24       parameters: pagination_params(),
25       operationId: "ScheduledActivity.index",
26       responses: %{
27         200 =>
28           Operation.response("Array of ScheduledStatus", "application/json", %Schema{
29             type: :array,
30             items: ScheduledStatus
31           })
32       }
33     }
34   end
35
36   def show_operation do
37     %Operation{
38       tags: ["Scheduled statuses"],
39       summary: "View a single scheduled status",
40       security: [%{"oAuth" => ["read:statuses"]}],
41       parameters: [id_param()],
42       operationId: "ScheduledActivity.show",
43       responses: %{
44         200 => Operation.response("Scheduled Status", "application/json", ScheduledStatus),
45         404 => Operation.response("Error", "application/json", ApiError)
46       }
47     }
48   end
49
50   def update_operation do
51     %Operation{
52       tags: ["Scheduled statuses"],
53       summary: "Schedule a status",
54       operationId: "ScheduledActivity.update",
55       security: [%{"oAuth" => ["write:statuses"]}],
56       parameters: [id_param()],
57       requestBody:
58         request_body("Parameters", %Schema{
59           type: :object,
60           properties: %{
61             scheduled_at: %Schema{
62               type: :string,
63               format: :"date-time",
64               description:
65                 "ISO 8601 Datetime at which the status will be published. Must be at least 5 minutes into the future."
66             }
67           }
68         }),
69       responses: %{
70         200 => Operation.response("Scheduled Status", "application/json", ScheduledStatus),
71         404 => Operation.response("Error", "application/json", ApiError)
72       }
73     }
74   end
75
76   def delete_operation do
77     %Operation{
78       tags: ["Scheduled statuses"],
79       summary: "Cancel a scheduled status",
80       security: [%{"oAuth" => ["write:statuses"]}],
81       parameters: [id_param()],
82       operationId: "ScheduledActivity.delete",
83       responses: %{
84         200 => Operation.response("Empty object", "application/json", %Schema{type: :object}),
85         404 => Operation.response("Error", "application/json", ApiError)
86       }
87     }
88   end
89
90   defp id_param do
91     Operation.parameter(:id, :path, FlakeID, "Poll ID",
92       example: "123",
93       required: true
94     )
95   end
96 end