1 defmodule Pleroma.Web.MastodonAPI.TagController do
2 @moduledoc "Hashtag routes for mastodon API"
3 use Pleroma.Web, :controller
8 plug(Pleroma.Web.ApiSpec.CastAndValidate)
9 plug(Pleroma.Web.Plugs.OAuthScopesPlug, %{scopes: ["read"]} when action in [:show])
12 Pleroma.Web.Plugs.OAuthScopesPlug,
13 %{scopes: ["write:follows"]} when action in [:follow, :unfollow]
16 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.TagOperation
18 def show(conn, %{id: id}) do
19 with %Hashtag{} = hashtag <- Hashtag.get_by_name(id) do
20 render(conn, "show.json", tag: hashtag, for_user: conn.assigns.user)
22 _ -> conn |> render_error(:not_found, "Hashtag not found")
26 def follow(conn, %{id: id}) do
27 with %Hashtag{} = hashtag <- Hashtag.get_by_name(id),
28 %User{} = user <- conn.assigns.user,
30 User.follow_hashtag(user, hashtag) do
31 render(conn, "show.json", tag: hashtag, for_user: user)
33 _ -> render_error(conn, :not_found, "Hashtag not found")
37 def unfollow(conn, %{id: id}) do
38 with %Hashtag{} = hashtag <- Hashtag.get_by_name(id),
39 %User{} = user <- conn.assigns.user,
41 User.unfollow_hashtag(user, hashtag) do
42 render(conn, "show.json", tag: hashtag, for_user: user)
44 _ -> render_error(conn, :not_found, "Hashtag not found")