mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 16:40:29 +00:00
Add Pleroma user search api for PleromaFE.
This commit is contained in:
parent
8456675c45
commit
7b170cd616
3 changed files with 29 additions and 1 deletions
|
@ -248,9 +248,15 @@ defmodule Pleroma.Web.Router do
|
||||||
)
|
)
|
||||||
|
|
||||||
get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
|
get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/api", Pleroma.Web do
|
scope "/api", Pleroma.Web, as: :twitter_api_search do
|
||||||
|
pipe_through(:api)
|
||||||
|
get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
|
||||||
pipe_through(:authenticated_api)
|
pipe_through(:authenticated_api)
|
||||||
|
|
||||||
get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
|
get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
|
||||||
|
|
|
@ -529,6 +529,13 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||||
|> render(ActivityView, "index.json", %{activities: activities, for: user})
|
|> render(ActivityView, "index.json", %{activities: activities, for: user})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search_user(%{assigns: %{user: user}} = conn, %{"query" => query}) do
|
||||||
|
users = User.search(query, true)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> render(UserView, "index.json", %{users: users, for: user})
|
||||||
|
end
|
||||||
|
|
||||||
defp bad_request_reply(conn, error_message) do
|
defp bad_request_reply(conn, error_message) do
|
||||||
json = error_json(conn, error_message)
|
json = error_json(conn, error_message)
|
||||||
json_reply(conn, 400, json)
|
json_reply(conn, 400, json)
|
||||||
|
|
|
@ -1211,4 +1211,19 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
||||||
assert relationship["follows_you"] == false
|
assert relationship["follows_you"] == false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "GET /api/pleroma/search_user" do
|
||||||
|
test "it returns users, ordered by similarity", %{conn: conn} do
|
||||||
|
user = insert(:user, %{name: "eal"})
|
||||||
|
user_two = insert(:user, %{name: "ean"})
|
||||||
|
user_three = insert(:user, %{name: "ebn"})
|
||||||
|
|
||||||
|
resp = conn
|
||||||
|
|> get(twitter_api_search__path(conn, :search_user), query: "eal")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
|
assert length(resp) == 3
|
||||||
|
assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn (%{"id" => id}) -> id end)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue