pleroma/lib/pleroma/web/mastodon_api/controllers/marker_controller.ex

39 lines
1.2 KiB
Elixir
Raw Normal View History

2019-10-17 14:26:59 +02:00
# Pleroma: A lightweight social networking server
2020-03-03 23:44:49 +01:00
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
2019-10-17 14:26:59 +02:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MarkerController do
use Pleroma.Web, :controller
2020-06-24 08:57:27 +02:00
alias Pleroma.Web.Plugs.OAuthScopesPlug
2019-10-17 14:26:59 +02:00
plug(Pleroma.Web.ApiSpec.CastAndValidate)
2019-10-17 14:26:59 +02:00
plug(
OAuthScopesPlug,
%{scopes: ["read:statuses"]}
when action == :index
)
plug(OAuthScopesPlug, %{scopes: ["write:statuses"]} when action == :upsert)
2019-10-17 14:26:59 +02:00
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
2020-04-14 20:50:29 +02:00
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.MarkerOperation
2019-10-17 14:26:59 +02:00
# GET /api/v1/markers
def index(%{assigns: %{user: user}} = conn, params) do
2020-04-14 20:50:29 +02:00
markers = Pleroma.Marker.get_markers(user, params[:timeline])
2019-10-17 14:26:59 +02:00
render(conn, "markers.json", %{markers: markers})
end
# POST /api/v1/markers
2020-04-14 20:50:29 +02:00
def upsert(%{assigns: %{user: user}, body_params: params} = conn, _) do
params = Map.new(params, fn {key, value} -> {to_string(key), value} end)
2020-04-14 20:50:29 +02:00
2019-10-17 14:26:59 +02:00
with {:ok, result} <- Pleroma.Marker.upsert(user, params),
markers <- Map.values(result) do
render(conn, "markers.json", %{markers: markers})
end
end
end