Commit a027b002 authored by lain's avatar lain
Browse files

Add friends endpoint.

parent 94a394e3
......@@ -72,6 +72,7 @@ def user_fetcher(username) do
post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar
get "/statuses/followers", TwitterAPI.Controller, :followers
get "/statuses/friends", TwitterAPI.Controller, :friends
end
pipeline :ostatus do
......
......@@ -218,6 +218,14 @@ def followers(%{assigns: %{user: user}} = conn, _params) do
end
end
def friends(%{assigns: %{user: user}} = conn, _params) do
with {:ok, friends} <- User.get_friends(user) do
render(conn, UserView, "index.json", %{users: friends, for: user})
else
_e -> bad_request_reply(conn, "Can't get friends")
end
end
defp bad_request_reply(conn, error_message) do
json = error_json(conn, error_message)
json_reply(conn, 400, json)
......
......@@ -437,6 +437,24 @@ test "it returns a user's followers", %{conn: conn} do
end
end
describe "GET /api/statuses/friends" do
test "it returns a user's friends", %{conn: conn} do
user = insert(:user)
followed_one = insert(:user)
followed_two = insert(:user)
not_followed = insert(:user)
{:ok, user} = User.follow(user, followed_one)
{:ok, user} = User.follow(user, followed_two)
conn = conn
|> assign(:user, user)
|> get("/api/statuses/friends")
assert json_response(conn, 200) == UserView.render("index.json", %{users: [followed_one, followed_two], for: user})
end
end
defp valid_user(_context) do
user = insert(:user)
[user: user]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment