MastoAPI: Add accounts getting.
This commit is contained in:
parent
ad5001828e
commit
d168ef5a9e
3 changed files with 40 additions and 13 deletions
|
@ -28,6 +28,17 @@ def verify_credentials(%{assigns: %{user: user}} = conn, params) do
|
||||||
json(conn, account)
|
json(conn, account)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user(conn, %{"id" => id}) do
|
||||||
|
with %User{} = user <- Repo.get(User, id) do
|
||||||
|
account = AccountView.render("account.json", %{user: user})
|
||||||
|
json(conn, account)
|
||||||
|
else
|
||||||
|
_e -> conn
|
||||||
|
|> put_status(404)
|
||||||
|
|> json(%{error: "Can't find user"})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def masto_instance(conn, _params) do
|
def masto_instance(conn, _params) do
|
||||||
response = %{
|
response = %{
|
||||||
uri: Web.base_url,
|
uri: Web.base_url,
|
||||||
|
|
|
@ -39,19 +39,6 @@ def user_fetcher(username) do
|
||||||
post "/token", OAuthController, :token_exchange
|
post "/token", OAuthController, :token_exchange
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
|
||||||
pipe_through :api
|
|
||||||
get "/instance", MastodonAPIController, :masto_instance
|
|
||||||
post "/apps", MastodonAPIController, :create_app
|
|
||||||
|
|
||||||
get "/timelines/public", MastodonAPIController, :public_timeline
|
|
||||||
|
|
||||||
get "/statuses/:id", MastodonAPIController, :get_status
|
|
||||||
get "/statuses/:id/context", MastodonAPIController, :get_context
|
|
||||||
|
|
||||||
get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
|
|
||||||
end
|
|
||||||
|
|
||||||
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
||||||
pipe_through :authenticated_api
|
pipe_through :authenticated_api
|
||||||
|
|
||||||
|
@ -70,6 +57,20 @@ def user_fetcher(username) do
|
||||||
get "/notifications", MastodonAPIController, :notifications
|
get "/notifications", MastodonAPIController, :notifications
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scope "/api/v1", Pleroma.Web.MastodonAPI do
|
||||||
|
pipe_through :api
|
||||||
|
get "/instance", MastodonAPIController, :masto_instance
|
||||||
|
post "/apps", MastodonAPIController, :create_app
|
||||||
|
|
||||||
|
get "/timelines/public", MastodonAPIController, :public_timeline
|
||||||
|
|
||||||
|
get "/statuses/:id", MastodonAPIController, :get_status
|
||||||
|
get "/statuses/:id/context", MastodonAPIController, :get_context
|
||||||
|
|
||||||
|
get "/accounts/:id/statuses", MastodonAPIController, :user_statuses
|
||||||
|
get "/accounts/:id", MastodonAPIController, :user
|
||||||
|
end
|
||||||
|
|
||||||
scope "/api", Pleroma.Web do
|
scope "/api", Pleroma.Web do
|
||||||
pipe_through :config
|
pipe_through :config
|
||||||
|
|
||||||
|
|
|
@ -198,4 +198,19 @@ test "returns the relationships for the current user", %{conn: conn} do
|
||||||
assert other_user.id == relationship["id"]
|
assert other_user.id == relationship["id"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "account fetching", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
conn = conn
|
||||||
|
|> get("/api/v1/accounts/#{user.id}")
|
||||||
|
|
||||||
|
assert %{"id" => id} = json_response(conn, 200)
|
||||||
|
assert id == user.id
|
||||||
|
|
||||||
|
conn = build_conn()
|
||||||
|
|> get("/api/v1/accounts/-1")
|
||||||
|
|
||||||
|
assert %{"error" => "Can't find user"} = json_response(conn, 404)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue