logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

announcement_operation.ex (5060B)


  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. defmodule Pleroma.Web.ApiSpec.Admin.AnnouncementOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.Announcement
  8. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  9. import Pleroma.Web.ApiSpec.Helpers
  10. def open_api_operation(action) do
  11. operation = String.to_existing_atom("#{action}_operation")
  12. apply(__MODULE__, operation, [])
  13. end
  14. def index_operation do
  15. %Operation{
  16. tags: ["Announcement management"],
  17. summary: "Retrieve a list of announcements",
  18. operationId: "AdminAPI.AnnouncementController.index",
  19. security: [%{"oAuth" => ["admin:read"]}],
  20. parameters: [
  21. Operation.parameter(
  22. :limit,
  23. :query,
  24. %Schema{type: :integer, minimum: 1},
  25. "the maximum number of announcements to return"
  26. ),
  27. Operation.parameter(
  28. :offset,
  29. :query,
  30. %Schema{type: :integer, minimum: 0},
  31. "the offset of the first announcement to return"
  32. )
  33. | admin_api_params()
  34. ],
  35. responses: %{
  36. 200 => Operation.response("Response", "application/json", list_of_announcements()),
  37. 400 => Operation.response("Forbidden", "application/json", ApiError),
  38. 403 => Operation.response("Forbidden", "application/json", ApiError)
  39. }
  40. }
  41. end
  42. def show_operation do
  43. %Operation{
  44. tags: ["Announcement management"],
  45. summary: "Display one announcement",
  46. operationId: "AdminAPI.AnnouncementController.show",
  47. security: [%{"oAuth" => ["admin:read"]}],
  48. parameters: [
  49. Operation.parameter(
  50. :id,
  51. :path,
  52. :string,
  53. "announcement id"
  54. )
  55. | admin_api_params()
  56. ],
  57. responses: %{
  58. 200 => Operation.response("Response", "application/json", Announcement),
  59. 403 => Operation.response("Forbidden", "application/json", ApiError),
  60. 404 => Operation.response("Not Found", "application/json", ApiError)
  61. }
  62. }
  63. end
  64. def delete_operation do
  65. %Operation{
  66. tags: ["Announcement management"],
  67. summary: "Delete one announcement",
  68. operationId: "AdminAPI.AnnouncementController.delete",
  69. security: [%{"oAuth" => ["admin:write"]}],
  70. parameters: [
  71. Operation.parameter(
  72. :id,
  73. :path,
  74. :string,
  75. "announcement id"
  76. )
  77. | admin_api_params()
  78. ],
  79. responses: %{
  80. 200 => Operation.response("Response", "application/json", %Schema{type: :object}),
  81. 403 => Operation.response("Forbidden", "application/json", ApiError),
  82. 404 => Operation.response("Not Found", "application/json", ApiError)
  83. }
  84. }
  85. end
  86. def create_operation do
  87. %Operation{
  88. tags: ["Announcement management"],
  89. summary: "Create one announcement",
  90. operationId: "AdminAPI.AnnouncementController.create",
  91. security: [%{"oAuth" => ["admin:write"]}],
  92. requestBody: request_body("Parameters", create_request(), required: true),
  93. responses: %{
  94. 200 => Operation.response("Response", "application/json", Announcement),
  95. 400 => Operation.response("Bad Request", "application/json", ApiError),
  96. 403 => Operation.response("Forbidden", "application/json", ApiError)
  97. }
  98. }
  99. end
  100. def change_operation do
  101. %Operation{
  102. tags: ["Announcement management"],
  103. summary: "Change one announcement",
  104. operationId: "AdminAPI.AnnouncementController.change",
  105. security: [%{"oAuth" => ["admin:write"]}],
  106. parameters: [
  107. Operation.parameter(
  108. :id,
  109. :path,
  110. :string,
  111. "announcement id"
  112. )
  113. | admin_api_params()
  114. ],
  115. requestBody: request_body("Parameters", change_request(), required: true),
  116. responses: %{
  117. 200 => Operation.response("Response", "application/json", Announcement),
  118. 400 => Operation.response("Bad Request", "application/json", ApiError),
  119. 403 => Operation.response("Forbidden", "application/json", ApiError),
  120. 404 => Operation.response("Not Found", "application/json", ApiError)
  121. }
  122. }
  123. end
  124. defp create_or_change_props do
  125. %{
  126. content: %Schema{type: :string},
  127. starts_at: %Schema{type: :string, format: "date-time", nullable: true},
  128. ends_at: %Schema{type: :string, format: "date-time", nullable: true},
  129. all_day: %Schema{type: :boolean}
  130. }
  131. end
  132. def create_request do
  133. %Schema{
  134. title: "AnnouncementCreateRequest",
  135. type: :object,
  136. required: [:content],
  137. properties: create_or_change_props()
  138. }
  139. end
  140. def change_request do
  141. %Schema{
  142. title: "AnnouncementChangeRequest",
  143. type: :object,
  144. properties: create_or_change_props()
  145. }
  146. end
  147. def list_of_announcements do
  148. %Schema{
  149. type: :array,
  150. items: Announcement
  151. }
  152. end
  153. end