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