summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormarcin mikołajczak <git@mkljczk.pl>2021-12-28 16:11:17 +0100
committermarcin mikołajczak <git@mkljczk.pl>2021-12-28 16:11:17 +0100
commitf734579965b6f1a635e0622356e9cf6d4fff00bb (patch)
treef71f3d56f7d0f9b034ed5c95c0f4cb4dd614d11e /lib
parent1fa616638b8823a6cc0d67d0354cc179da5943f8 (diff)
MastoAPI: Add `GET /api/v1/accounts/lookup`
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/api_spec/operations/account_operation.ex20
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/account_controller.ex12
-rw-r--r--lib/pleroma/web/router.ex2
3 files changed, 34 insertions, 0 deletions
diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex
index 54e5ebc76..5836cab50 100644
--- a/lib/pleroma/web/api_spec/operations/account_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/account_operation.ex
@@ -371,6 +371,26 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
}
end
+ def lookup_operation do
+ %Operation{
+ tags: ["Account lookup"],
+ summary: "Find a user by nickname",
+ operationId: "AccountController.lookup",
+ parameters: [
+ Operation.parameter(
+ :acct,
+ :query,
+ :string,
+ "User nickname"
+ )
+ ],
+ responses: %{
+ 200 => Operation.response("Account", "application/json", Account),
+ 404 => Operation.response("Error", "application/json", ApiError)
+ }
+ }
+ end
+
def endorsements_operation do
%Operation{
tags: ["Retrieve account information"],
diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
index 5fcbffc34..3eae0a646 100644
--- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex
@@ -477,6 +477,18 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|> render("index.json", users: users, for: user, as: :user)
end
+ @doc "GET /api/v1/accounts/lookup"
+ def lookup(%{assigns: %{user: for_user}} = conn, %{acct: nickname} = _params) do
+ with %User{} = user <- User.get_by_nickname(nickname) do
+ render(conn, "show.json",
+ user: user,
+ for: for_user
+ )
+ else
+ error -> user_visibility_error(conn, error)
+ end
+ end
+
@doc "GET /api/v1/endorsements"
def endorsements(conn, params), do: MastodonAPIController.empty_array(conn, params)
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 5fbc2509e..ae373e58c 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -573,6 +573,8 @@ defmodule Pleroma.Web.Router do
get("/accounts/search", SearchController, :account_search)
get("/search", SearchController, :search)
+ get("/accounts/lookup", AccountController, :lookup)
+
get("/accounts/:id/statuses", AccountController, :statuses)
get("/accounts/:id/followers", AccountController, :followers)
get("/accounts/:id/following", AccountController, :following)