Update Copyrights
[akkoma] / lib / pleroma / web / mastodon_api / controllers / marker_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.MarkerController do
6 use Pleroma.Web, :controller
7 alias Pleroma.Plugs.OAuthScopesPlug
8
9 plug(
10 OAuthScopesPlug,
11 %{scopes: ["read:statuses"]}
12 when action == :index
13 )
14
15 plug(OAuthScopesPlug, %{scopes: ["write:statuses"]} when action == :upsert)
16 plug(Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug)
17 action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
18
19 # GET /api/v1/markers
20 def index(%{assigns: %{user: user}} = conn, params) do
21 markers = Pleroma.Marker.get_markers(user, params["timeline"])
22 render(conn, "markers.json", %{markers: markers})
23 end
24
25 # POST /api/v1/markers
26 def upsert(%{assigns: %{user: user}} = conn, params) do
27 with {:ok, result} <- Pleroma.Marker.upsert(user, params),
28 markers <- Map.values(result) do
29 render(conn, "markers.json", %{markers: markers})
30 end
31 end
32 end