Add followers endpoint.
This commit is contained in:
parent
44aef2183e
commit
94a394e3a8
|
@ -70,6 +70,8 @@ def user_fetcher(username) do
|
||||||
post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
|
post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
|
||||||
|
|
||||||
post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
|
post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
|
||||||
|
|
||||||
|
get "/statuses/followers", TwitterAPI.Controller, :followers
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :ostatus do
|
pipeline :ostatus do
|
||||||
|
|
|
@ -210,6 +210,14 @@ def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" =>
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def followers(%{assigns: %{user: user}} = conn, _params) do
|
||||||
|
with {:ok, followers} <- User.get_followers(user) do
|
||||||
|
render(conn, UserView, "index.json", %{users: followers, for: user})
|
||||||
|
else
|
||||||
|
_e -> bad_request_reply(conn, "Can't get followers")
|
||||||
|
end
|
||||||
|
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)
|
||||||
|
|
|
@ -4,6 +4,14 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
|
||||||
alias Pleroma.Web.TwitterAPI.Utils
|
alias Pleroma.Web.TwitterAPI.Utils
|
||||||
|
|
||||||
def render("show.json", %{user: user = %User{}} = assigns) do
|
def render("show.json", %{user: user = %User{}} = assigns) do
|
||||||
|
render_one(user, Pleroma.Web.TwitterAPI.UserView, "user.json", assigns)
|
||||||
|
end
|
||||||
|
|
||||||
|
def render("index.json", %{users: users, for: user}) do
|
||||||
|
render_many(users, Pleroma.Web.TwitterAPI.UserView, "user.json", for: user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
image = User.avatar_url(user)
|
image = User.avatar_url(user)
|
||||||
following = if assigns[:for] do
|
following = if assigns[:for] do
|
||||||
User.following?(assigns[:for], user)
|
User.following?(assigns[:for], user)
|
||||||
|
|
|
@ -419,6 +419,24 @@ test "it returns the user", %{conn: conn} do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "GET /api/statuses/followers" do
|
||||||
|
test "it returns a user's followers", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
follower_one = insert(:user)
|
||||||
|
follower_two = insert(:user)
|
||||||
|
not_follower = insert(:user)
|
||||||
|
|
||||||
|
{:ok, follower_one} = User.follow(follower_one, user)
|
||||||
|
{:ok, follower_two} = User.follow(follower_two, user)
|
||||||
|
|
||||||
|
conn = conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> get("/api/statuses/followers")
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == UserView.render("index.json", %{users: [follower_one, follower_two], for: user})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp valid_user(_context) do
|
defp valid_user(_context) do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
[user: user]
|
[user: user]
|
||||||
|
|
Loading…
Reference in New Issue