1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.Admin.AnnouncementOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Announcement
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
11 import Pleroma.Web.ApiSpec.Helpers
13 def open_api_operation(action) do
14 operation = String.to_existing_atom("#{action}_operation")
15 apply(__MODULE__, operation, [])
18 def index_operation do
20 tags: ["Announcement management"],
21 summary: "Retrieve a list of announcements",
22 operationId: "AdminAPI.AnnouncementController.index",
23 security: [%{"oAuth" => ["admin:read"]}],
28 %Schema{type: :integer, minimum: 1},
29 "the maximum number of announcements to return"
34 %Schema{type: :integer, minimum: 0},
35 "the offset of the first announcement to return"
40 200 => Operation.response("Response", "application/json", list_of_announcements()),
41 400 => Operation.response("Forbidden", "application/json", ApiError),
42 403 => Operation.response("Forbidden", "application/json", ApiError)
49 tags: ["Announcement management"],
50 summary: "Display one announcement",
51 operationId: "AdminAPI.AnnouncementController.show",
52 security: [%{"oAuth" => ["admin:read"]}],
63 200 => Operation.response("Response", "application/json", Announcement),
64 403 => Operation.response("Forbidden", "application/json", ApiError),
65 404 => Operation.response("Not Found", "application/json", ApiError)
70 def delete_operation do
72 tags: ["Announcement management"],
73 summary: "Delete one announcement",
74 operationId: "AdminAPI.AnnouncementController.delete",
75 security: [%{"oAuth" => ["admin:write"]}],
86 200 => Operation.response("Response", "application/json", %Schema{type: :object}),
87 403 => Operation.response("Forbidden", "application/json", ApiError),
88 404 => Operation.response("Not Found", "application/json", ApiError)
93 def create_operation do
95 tags: ["Announcement management"],
96 summary: "Create one announcement",
97 operationId: "AdminAPI.AnnouncementController.create",
98 security: [%{"oAuth" => ["admin:write"]}],
99 requestBody: request_body("Parameters", create_request(), required: true),
101 200 => Operation.response("Response", "application/json", Announcement),
102 400 => Operation.response("Bad Request", "application/json", ApiError),
103 403 => Operation.response("Forbidden", "application/json", ApiError)
108 def change_operation do
110 tags: ["Announcement management"],
111 summary: "Change one announcement",
112 operationId: "AdminAPI.AnnouncementController.change",
113 security: [%{"oAuth" => ["admin:write"]}],
123 requestBody: request_body("Parameters", change_request(), required: true),
125 200 => Operation.response("Response", "application/json", Announcement),
126 400 => Operation.response("Bad Request", "application/json", ApiError),
127 403 => Operation.response("Forbidden", "application/json", ApiError),
128 404 => Operation.response("Not Found", "application/json", ApiError)
133 defp create_or_change_props do
135 content: %Schema{type: :string},
136 starts_at: %Schema{type: :string, format: "date-time", nullable: true},
137 ends_at: %Schema{type: :string, format: "date-time", nullable: true},
138 all_day: %Schema{type: :boolean}
142 def create_request do
144 title: "AnnouncementCreateRequest",
146 required: [:content],
147 properties: create_or_change_props()
151 def change_request do
153 title: "AnnouncementChangeRequest",
155 properties: create_or_change_props()
159 def list_of_announcements do