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

39 lines
1.2 KiB
Elixir
Raw Normal View History

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