logo

pleroma

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

poll_operation.ex (2103B)


  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.PollOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  8. alias Pleroma.Web.ApiSpec.Schemas.FlakeID
  9. alias Pleroma.Web.ApiSpec.Schemas.Poll
  10. import Pleroma.Web.ApiSpec.Helpers
  11. def open_api_operation(action) do
  12. operation = String.to_existing_atom("#{action}_operation")
  13. apply(__MODULE__, operation, [])
  14. end
  15. def show_operation do
  16. %Operation{
  17. tags: ["Polls"],
  18. summary: "View a poll",
  19. security: [%{"oAuth" => ["read:statuses"]}],
  20. parameters: [id_param()],
  21. operationId: "PollController.show",
  22. responses: %{
  23. 200 => Operation.response("Poll", "application/json", Poll),
  24. 404 => Operation.response("Error", "application/json", ApiError)
  25. }
  26. }
  27. end
  28. def vote_operation do
  29. %Operation{
  30. tags: ["Polls"],
  31. summary: "Vote on a poll",
  32. parameters: [id_param()],
  33. operationId: "PollController.vote",
  34. requestBody: vote_request(),
  35. security: [%{"oAuth" => ["write:statuses"]}],
  36. responses: %{
  37. 200 => Operation.response("Poll", "application/json", Poll),
  38. 422 => Operation.response("Error", "application/json", ApiError),
  39. 404 => Operation.response("Error", "application/json", ApiError)
  40. }
  41. }
  42. end
  43. defp id_param do
  44. Operation.parameter(:id, :path, FlakeID.schema(), "Poll ID",
  45. example: "123",
  46. required: true
  47. )
  48. end
  49. defp vote_request do
  50. request_body(
  51. "Parameters",
  52. %Schema{
  53. type: :object,
  54. properties: %{
  55. choices: %Schema{
  56. type: :array,
  57. items: %Schema{type: :integer},
  58. description: "Array of own votes containing index for each option (starting from 0)"
  59. }
  60. },
  61. required: [:choices]
  62. },
  63. required: true,
  64. example: %{
  65. "choices" => [0, 1, 2]
  66. }
  67. )
  68. end
  69. end