add metadata endpoint
This commit is contained in:
parent
509924ed52
commit
82153b283b
|
@ -108,6 +108,14 @@ defmodule Backend.Api do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list_instance_types() do
|
||||||
|
Instance
|
||||||
|
|> select([i], i.type)
|
||||||
|
|> where([i], not is_nil(i.type))
|
||||||
|
|> distinct(true)
|
||||||
|
|> Repo.all()
|
||||||
|
end
|
||||||
|
|
||||||
def search_instances(query, filters, from \\ 0) do
|
def search_instances(query, filters, from \\ 0) do
|
||||||
page_size = 50
|
page_size = 50
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,6 @@ defmodule Backend.Util do
|
||||||
@spec get_last_crawl(String.t()) :: Crawl.t() | nil
|
@spec get_last_crawl(String.t()) :: Crawl.t() | nil
|
||||||
def get_last_crawl(domain) do
|
def get_last_crawl(domain) do
|
||||||
Crawl
|
Crawl
|
||||||
|> select([c], c)
|
|
||||||
|> where([c], c.instance_domain == ^domain)
|
|> where([c], c.instance_domain == ^domain)
|
||||||
|> order_by(desc: :id)
|
|> order_by(desc: :id)
|
||||||
|> limit(1)
|
|> limit(1)
|
||||||
|
|
11
backend/lib/backend_web/controllers/metadata_controller.ex
Normal file
11
backend/lib/backend_web/controllers/metadata_controller.ex
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
defmodule BackendWeb.MetadataController do
|
||||||
|
use BackendWeb, :controller
|
||||||
|
alias Backend.Api
|
||||||
|
|
||||||
|
action_fallback BackendWeb.FallbackController
|
||||||
|
|
||||||
|
def index(conn, _params) do
|
||||||
|
instance_types = Api.list_instance_types()
|
||||||
|
render(conn, "index.json", instance_types: instance_types)
|
||||||
|
end
|
||||||
|
end
|
|
@ -8,6 +8,7 @@ defmodule BackendWeb.Router do
|
||||||
scope "/api", BackendWeb do
|
scope "/api", BackendWeb do
|
||||||
pipe_through(:api)
|
pipe_through(:api)
|
||||||
|
|
||||||
|
resources("/metadata", MetadataController, only: [:index])
|
||||||
resources("/instances", InstanceController, only: [:show])
|
resources("/instances", InstanceController, only: [:show])
|
||||||
resources("/graph", GraphController, only: [:index, :show])
|
resources("/graph", GraphController, only: [:index, :show])
|
||||||
resources("/search", SearchController, only: [:index])
|
resources("/search", SearchController, only: [:index])
|
||||||
|
|
|
@ -26,7 +26,12 @@ defmodule BackendWeb.InstanceView do
|
||||||
}
|
}
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
last_updated = max_datetime(crawl.inserted_at, instance.updated_at)
|
last_updated =
|
||||||
|
if crawl == nil do
|
||||||
|
instance.updated_at
|
||||||
|
else
|
||||||
|
max_datetime(crawl.inserted_at, instance.updated_at)
|
||||||
|
end
|
||||||
|
|
||||||
filtered_peers =
|
filtered_peers =
|
||||||
instance.peers
|
instance.peers
|
||||||
|
|
9
backend/lib/backend_web/views/metadata_view.ex
Normal file
9
backend/lib/backend_web/views/metadata_view.ex
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule BackendWeb.MetadataView do
|
||||||
|
use BackendWeb, :view
|
||||||
|
|
||||||
|
def render("index.json", %{instance_types: instance_types}) do
|
||||||
|
%{
|
||||||
|
instanceTypes: instance_types
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue