+ 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
+
+ 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
+
+ def update_profile(%{assigns: %{user: user}} = conn, params) do
+ params = if bio = params["description"] do
+ Map.put(params, "bio", bio)
+ else
+ params
+ end
+
+ with changeset <- User.update_changeset(user, params),
+ {:ok, user} <- Repo.update(changeset) do
+ render(conn, UserView, "user.json", %{user: user, for: user})
+ else
+ error ->
+ Logger.debug("Can't update user: #{inspect(error)}")
+ bad_request_reply(conn, "Can't update user")
+ end
+ end
+