Add OpenAPI spec for ReportController
[akkoma] / lib / pleroma / web / mastodon_api / controllers / report_controller.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.MastodonAPI.ReportController do
6 alias Pleroma.Plugs.OAuthScopesPlug
7
8 use Pleroma.Web, :controller
9
10 action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
11
12 plug(OpenApiSpex.Plug.CastAndValidate, render_error: Pleroma.Web.ApiSpec.RenderError)
13 plug(OAuthScopesPlug, %{scopes: ["write:reports"]} when action == :create)
14 plug(Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug)
15
16 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.ReportOperation
17
18 @doc "POST /api/v1/reports"
19 def create(%{assigns: %{user: user}, body_params: params} = conn, _) do
20 with {:ok, activity} <- Pleroma.Web.CommonAPI.report(user, params) do
21 render(conn, "show.json", activity: activity)
22 end
23 end
24 end