summaryrefslogtreecommitdiff
path: root/lib/pleroma/web/api_spec/operations/scheduled_activity_operation.ex
blob: b9c5b35c15a020a1c41dcffaf4478d3e3171531b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.ApiSpec.ScheduledActivityOperation do
  alias OpenApiSpex.Operation
  alias OpenApiSpex.Schema
  alias Pleroma.Web.ApiSpec.Schemas.ApiError
  alias Pleroma.Web.ApiSpec.Schemas.FlakeID
  alias Pleroma.Web.ApiSpec.Schemas.ScheduledStatus

  import Pleroma.Web.ApiSpec.Helpers

  def open_api_operation(action) do
    operation = String.to_existing_atom("#{action}_operation")
    apply(__MODULE__, operation, [])
  end

  def index_operation do
    %Operation{
      tags: ["Scheduled statuses"],
      summary: "View scheduled statuses",
      security: [%{"oAuth" => ["read:statuses"]}],
      parameters: pagination_params(),
      operationId: "ScheduledActivity.index",
      responses: %{
        200 =>
          Operation.response("Array of ScheduledStatus", "application/json", %Schema{
            type: :array,
            items: ScheduledStatus
          })
      }
    }
  end

  def show_operation do
    %Operation{
      tags: ["Scheduled statuses"],
      summary: "View a single scheduled status",
      security: [%{"oAuth" => ["read:statuses"]}],
      parameters: [id_param()],
      operationId: "ScheduledActivity.show",
      responses: %{
        200 => Operation.response("Scheduled Status", "application/json", ScheduledStatus),
        404 => Operation.response("Error", "application/json", ApiError)
      }
    }
  end

  def update_operation do
    %Operation{
      tags: ["Scheduled statuses"],
      summary: "Schedule a status",
      operationId: "ScheduledActivity.update",
      security: [%{"oAuth" => ["write:statuses"]}],
      parameters: [id_param()],
      requestBody:
        request_body("Parameters", %Schema{
          type: :object,
          properties: %{
            scheduled_at: %Schema{
              type: :string,
              format: :"date-time",
              description:
                "ISO 8601 Datetime at which the status will be published. Must be at least 5 minutes into the future."
            }
          }
        }),
      responses: %{
        200 => Operation.response("Scheduled Status", "application/json", ScheduledStatus),
        404 => Operation.response("Error", "application/json", ApiError)
      }
    }
  end

  def delete_operation do
    %Operation{
      tags: ["Scheduled statuses"],
      summary: "Cancel a scheduled status",
      security: [%{"oAuth" => ["write:statuses"]}],
      parameters: [id_param()],
      operationId: "ScheduledActivity.delete",
      responses: %{
        200 => Operation.response("Empty object", "application/json", %Schema{type: :object}),
        404 => Operation.response("Error", "application/json", ApiError)
      }
    }
  end

  defp id_param do
    Operation.parameter(:id, :path, FlakeID, "Poll ID",
      example: "123",
      required: true
    )
  end
end