post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
+
+ get "/statuses/followers", TwitterAPI.Controller, :followers
end
pipeline :ostatus do
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
json = error_json(conn, error_message)
json_reply(conn, 400, json)
alias Pleroma.Web.TwitterAPI.Utils
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)
following = if assigns[:for] do
User.following?(assigns[:for], user)
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
user = insert(:user)
[user: user]