Cleanup PleromaAPIController
[akkoma] / lib / pleroma / web / pleroma_api / subscription_notification_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationController do
6 use Pleroma.Web, :controller
7
8 import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
9
10 alias Pleroma.SubscriptionNotification
11 alias Pleroma.Web.PleromaAPI.PleromaAPI
12
13 def list(%{assigns: %{user: user}} = conn, params) do
14 notifications = PleromaAPI.get_subscription_notifications(user, params)
15
16 conn
17 |> add_link_headers(notifications)
18 |> render("index.json", %{notifications: notifications, for: user})
19 end
20
21 def get(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
22 with {:ok, notification} <- SubscriptionNotification.get(user, id) do
23 render(conn, "show.json", %{subscription_notification: notification, for: user})
24 else
25 {:error, reason} ->
26 conn
27 |> put_status(:forbidden)
28 |> json(%{"error" => reason})
29 end
30 end
31
32 def clear(%{assigns: %{user: user}} = conn, _params) do
33 SubscriptionNotification.clear(user)
34 json(conn, %{})
35 end
36
37 def dismiss(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
38 with {:ok, _notif} <- SubscriptionNotification.dismiss(user, id) do
39 json(conn, %{})
40 else
41 {:error, reason} ->
42 conn
43 |> put_status(:forbidden)
44 |> json(%{"error" => reason})
45 end
46 end
47
48 def destroy_multiple(
49 %{assigns: %{user: user}} = conn,
50 %{"ids" => ids} = _params
51 ) do
52 SubscriptionNotification.destroy_multiple(user, ids)
53 json(conn, %{})
54 end
55 end