Move reaction actions to EmojiReactionController
[akkoma] / lib / pleroma / web / api_spec / operations / emoji_reaction_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Account
9 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
10 alias Pleroma.Web.ApiSpec.Schemas.Status
11
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
15 end
16
17 def index_operation do
18 %Operation{
19 tags: ["Emoji Reactions"],
20 summary:
21 "Get an object of emoji to account mappings with accounts that reacted to the post",
22 parameters: [
23 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
24 Operation.parameter(:emoji, :path, :string, "Filter by a single unicode emoji",
25 required: false
26 )
27 ],
28 security: [%{"oAuth" => ["read:statuses"]}],
29 operationId: "EmojiReactionController.index",
30 responses: %{
31 200 => array_of_reactions_response()
32 }
33 }
34 end
35
36 def create_operation do
37 %Operation{
38 tags: ["Emoji Reactions"],
39 summary: "React to a post with a unicode emoji",
40 parameters: [
41 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
42 Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
43 required: true
44 )
45 ],
46 security: [%{"oAuth" => ["write:statuses"]}],
47 operationId: "EmojiReactionController.create",
48 responses: %{
49 200 => Operation.response("Status", "application/json", Status)
50 }
51 }
52 end
53
54 def delete_operation do
55 %Operation{
56 tags: ["Emoji Reactions"],
57 summary: "Remove a reaction to a post with a unicode emoji",
58 parameters: [
59 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
60 Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
61 required: true
62 )
63 ],
64 security: [%{"oAuth" => ["write:statuses"]}],
65 operationId: "EmojiReactionController.delete",
66 responses: %{
67 200 => Operation.response("Status", "application/json", Status)
68 }
69 }
70 end
71
72 defp array_of_reactions_response do
73 Operation.response("Array of Emoji Reactions", "application/json", %Schema{
74 type: :array,
75 items: emoji_reaction(),
76 example: [emoji_reaction().example]
77 })
78 end
79
80 defp emoji_reaction do
81 %Schema{
82 title: "EmojiReaction",
83 type: :object,
84 properties: %{
85 name: %Schema{type: :string, description: "Emoji"},
86 count: %Schema{type: :integer, description: "Count of reactions with this emoji"},
87 me: %Schema{type: :boolean, description: "Did I react with this emoji?"},
88 accounts: %Schema{
89 type: :array,
90 items: Account,
91 description: "Array of accounts reacted with this emoji"
92 }
93 },
94 example: %{
95 "name" => "😱",
96 "count" => 1,
97 "me" => false,
98 "accounts" => [Account.schema().example]
99 }
100 }
101 end
102 end