Remove deps from Streaming/Persisting behaviors
[akkoma] / lib / pleroma / web / pleroma_api / controllers / backup_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.PleromaAPI.BackupController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.User.Backup
9 alias Pleroma.Web.Plugs.OAuthScopesPlug
10
11 action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
12 plug(OAuthScopesPlug, %{scopes: ["read:accounts"]} when action in [:index, :create])
13 plug(OpenApiSpex.Plug.CastAndValidate, render_error: Pleroma.Web.ApiSpec.RenderError)
14
15 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaBackupOperation
16
17 def index(%{assigns: %{user: user}} = conn, _params) do
18 backups = Backup.list(user)
19 render(conn, "index.json", backups: backups)
20 end
21
22 def create(%{assigns: %{user: user}} = conn, _params) do
23 with {:ok, _} <- Backup.create(user) do
24 backups = Backup.list(user)
25 render(conn, "index.json", backups: backups)
26 end
27 end
28 end