summaryrefslogtreecommitdiff
path: root/lib/pleroma/web/api_spec/operations/pleroma_notification_operation.ex
blob: 1dda3924095d3e93c67738f73673cd197bb12acb (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
# 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.PleromaNotificationOperation do
  alias OpenApiSpex.Operation
  alias OpenApiSpex.Schema
  alias Pleroma.Web.ApiSpec.NotificationOperation
  alias Pleroma.Web.ApiSpec.Schemas.ApiError

  import Pleroma.Web.ApiSpec.Helpers

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

  def mark_as_read_operation do
    %Operation{
      tags: ["Notifications"],
      summary: "Mark notifications as read",
      description: "Query parameters are mutually exclusive.",
      requestBody:
        request_body("Parameters", %Schema{
          type: :object,
          properties: %{
            id: %Schema{type: :integer, description: "A single notification ID to read"},
            max_id: %Schema{type: :integer, description: "Read all notifications up to this ID"}
          }
        }),
      security: [%{"oAuth" => ["write:notifications"]}],
      operationId: "PleromaAPI.NotificationController.mark_as_read",
      responses: %{
        200 =>
          Operation.response(
            "A Notification or array of Notifications",
            "application/json",
            %Schema{
              anyOf: [
                %Schema{type: :array, items: NotificationOperation.notification()},
                NotificationOperation.notification()
              ]
            }
          ),
        400 => Operation.response("Bad Request", "application/json", ApiError)
      }
    }
  end
end