fediverse.space/backend/lib/backend_web/controllers/admin_controller.ex

34 wiersze
863 B
Elixir
Czysty Zwykły widok Historia

2019-07-26 14:34:23 +00:00
defmodule BackendWeb.AdminController do
2019-08-21 12:30:47 +00:00
alias Backend.{Api, Auth, Instance}
2019-07-26 14:34:23 +00:00
use BackendWeb, :controller
action_fallback BackendWeb.FallbackController
def show(conn, _params) do
[token] = get_req_header(conn, "token")
with {:ok, domain} <- Auth.verify_token(token) do
2019-08-23 13:08:05 +00:00
instance = Api.get_instance(domain)
2019-07-26 14:34:23 +00:00
render(conn, "show.json", instance: instance)
end
end
def update(conn, params) do
[token] = get_req_header(conn, "token")
with {:ok, domain} <- Auth.verify_token(token) do
%{"optIn" => opt_in, "optOut" => opt_out} = params
ecto_instance = %Instance{
2019-07-26 14:34:23 +00:00
domain: domain,
opt_in: opt_in,
opt_out: opt_out
}
with {:ok, updated_instance} <- Api.update_instance(ecto_instance) do
2019-07-26 14:34:23 +00:00
render(conn, "show.json", instance: updated_instance)
end
end
end
end