2019-07-14 11:47:06 +00:00
|
|
|
defmodule BackendWeb.InstanceController do
|
|
|
|
use BackendWeb, :controller
|
2019-08-27 13:50:16 +00:00
|
|
|
alias Backend.Api
|
2019-08-21 15:47:45 +00:00
|
|
|
alias Graph.Cache
|
2019-07-14 11:47:06 +00:00
|
|
|
|
2019-07-19 18:19:53 +00:00
|
|
|
action_fallback(BackendWeb.FallbackController)
|
2019-07-14 11:47:06 +00:00
|
|
|
|
2019-08-27 13:50:16 +00:00
|
|
|
def index(conn, params) do
|
|
|
|
page = Map.get(params, "page")
|
|
|
|
|
|
|
|
%{
|
|
|
|
entries: instances,
|
|
|
|
total_pages: total_pages,
|
|
|
|
page_number: page_number,
|
|
|
|
total_entries: total_entries,
|
|
|
|
page_size: page_size
|
|
|
|
} = Api.get_instances(page)
|
|
|
|
|
|
|
|
render(conn, "index.json",
|
|
|
|
instances: instances,
|
|
|
|
total_pages: total_pages,
|
|
|
|
page_number: page_number,
|
|
|
|
total_entries: total_entries,
|
|
|
|
page_size: page_size
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-07-14 11:47:06 +00:00
|
|
|
def show(conn, %{"id" => domain}) do
|
2019-08-21 15:47:45 +00:00
|
|
|
instance = Cache.get_instance_with_peers(domain)
|
2019-08-02 21:09:09 +00:00
|
|
|
|
|
|
|
if instance == nil or instance.opt_out == true do
|
|
|
|
send_resp(conn, 404, "Not found")
|
|
|
|
else
|
2019-08-21 15:47:45 +00:00
|
|
|
last_crawl = Cache.get_last_crawl(domain)
|
2019-08-02 21:09:09 +00:00
|
|
|
render(conn, "show.json", instance: instance, crawl: last_crawl)
|
|
|
|
end
|
2019-07-14 11:47:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# def update(conn, %{"id" => id, "instance" => instance_params}) do
|
|
|
|
# instance = Api.get_instance!(id)
|
|
|
|
|
|
|
|
# with {:ok, %Instance{} = instance} <- Api.update_instance(instance, instance_params) do
|
|
|
|
# render(conn, "show.json", instance: instance)
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
end
|