diff --git a/backend/lib/backend/api.ex b/backend/lib/backend/api.ex index 702f17e..244b0c6 100644 --- a/backend/lib/backend/api.ex +++ b/backend/lib/backend/api.ex @@ -108,6 +108,14 @@ defmodule Backend.Api do 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 page_size = 50 diff --git a/backend/lib/backend/util.ex b/backend/lib/backend/util.ex index b98de1d..5251f72 100644 --- a/backend/lib/backend/util.ex +++ b/backend/lib/backend/util.ex @@ -79,7 +79,6 @@ defmodule Backend.Util do @spec get_last_crawl(String.t()) :: Crawl.t() | nil def get_last_crawl(domain) do Crawl - |> select([c], c) |> where([c], c.instance_domain == ^domain) |> order_by(desc: :id) |> limit(1) diff --git a/backend/lib/backend_web/controllers/metadata_controller.ex b/backend/lib/backend_web/controllers/metadata_controller.ex new file mode 100644 index 0000000..09244d1 --- /dev/null +++ b/backend/lib/backend_web/controllers/metadata_controller.ex @@ -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 diff --git a/backend/lib/backend_web/router.ex b/backend/lib/backend_web/router.ex index dfa4f01..2fbbf00 100644 --- a/backend/lib/backend_web/router.ex +++ b/backend/lib/backend_web/router.ex @@ -8,6 +8,7 @@ defmodule BackendWeb.Router do scope "/api", BackendWeb do pipe_through(:api) + resources("/metadata", MetadataController, only: [:index]) resources("/instances", InstanceController, only: [:show]) resources("/graph", GraphController, only: [:index, :show]) resources("/search", SearchController, only: [:index]) diff --git a/backend/lib/backend_web/views/instance_view.ex b/backend/lib/backend_web/views/instance_view.ex index bb8ef8d..23eebc3 100644 --- a/backend/lib/backend_web/views/instance_view.ex +++ b/backend/lib/backend_web/views/instance_view.ex @@ -26,7 +26,12 @@ defmodule BackendWeb.InstanceView do } 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 = instance.peers diff --git a/backend/lib/backend_web/views/metadata_view.ex b/backend/lib/backend_web/views/metadata_view.ex new file mode 100644 index 0000000..75a3afe --- /dev/null +++ b/backend/lib/backend_web/views/metadata_view.ex @@ -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