From ea556abc81c07546c93b0e56684cea1b50328e4e Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Fri, 12 Dec 2025 16:15:27 +0000 Subject: [PATCH 1/2] api: endpoint for single stack status --- lib/ethui/stacks/server.ex | 11 ++++++++++ .../controllers/api/stack_controller.ex | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/ethui/stacks/server.ex b/lib/ethui/stacks/server.ex index ca28bf8..c46cafd 100644 --- a/lib/ethui/stacks/server.ex +++ b/lib/ethui/stacks/server.ex @@ -35,6 +35,12 @@ defmodule Ethui.Stacks.Server do GenServer.call(__MODULE__, :list) end + @doc "Check if a stack with the given slug is running" + @spec is_slug_running?(slug) :: boolean + def is_slug_running?(slug) do + GenServer.call(__MODULE__, {:is_slug_running, slug}) + end + def start(%Stack{} = stack) do GenServer.cast(__MODULE__, {:start, stack}) end @@ -92,6 +98,11 @@ defmodule Ethui.Stacks.Server do {:reply, Map.keys(instances), state} end + @impl GenServer + def handle_call({:is_slug_running, slug}, _from, %{instances: instances} = state) do + {:reply, Map.has_key?(instances, slug), state} + end + @impl GenServer def handle_cast({:start, stack}, state) do case start_stack(stack, state) do diff --git a/lib/ethui_web/controllers/api/stack_controller.ex b/lib/ethui_web/controllers/api/stack_controller.ex index 1ffbfa5..3c04dba 100644 --- a/lib/ethui_web/controllers/api/stack_controller.ex +++ b/lib/ethui_web/controllers/api/stack_controller.ex @@ -32,6 +32,28 @@ defmodule EthuiWeb.Api.StackController do }) end + def show(conn, %{"slug" => slug}) do + user = conn.assigns[:current_user] + + with %Stack{} = stack <- Repo.get_by(Stack, slug: slug), + :ok <- authorize_user_access(user, stack) do + json(conn, %{ + status: "success", + data: %{ + slug: stack.slug, + urls: Stacks.get_urls(stack), + status: if(Server.is_slug_running?(slug), do: "running", else: "stopped") + } + }) + else + nil -> + conn |> put_status(404) |> json(%{status: "error", error: "not found"}) + + {:error, :unauthorized} -> + conn |> put_status(403) |> json(%{status: "error", error: "unauthorized"}) + end + end + def create(conn, params) do user = conn.assigns[:current_user] From ab5f636cd03958deb816f77e2bffb8a28711fb9c Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Fri, 12 Dec 2025 16:22:33 +0000 Subject: [PATCH 2/2] wip --- server/test/ethui/stacks/server_test.exs | 13 +++++++++++++ .../controllers/api/stack_controller_test.exs | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/server/test/ethui/stacks/server_test.exs b/server/test/ethui/stacks/server_test.exs index db70a4d..33627d6 100644 --- a/server/test/ethui/stacks/server_test.exs +++ b/server/test/ethui/stacks/server_test.exs @@ -40,4 +40,17 @@ defmodule Ethui.Stacks.ServerTest do Server.stop(stack) assert Server.list() |> length == 0 end + + describe "is_running?/1" do + test "returns true if the stack is running" do + stack = %Stack{id: 1, slug: "test_stack"} + Server.start(stack) + assert Server.is_running?(stack) + end + + test "returns false if the stack is not running" do + stack = %Stack{id: 1, slug: "test_stack"} + assert not Server.is_running?(stack) + end + end end diff --git a/server/test/ethui_web/controllers/api/stack_controller_test.exs b/server/test/ethui_web/controllers/api/stack_controller_test.exs index 608bf18..924d4e0 100644 --- a/server/test/ethui_web/controllers/api/stack_controller_test.exs +++ b/server/test/ethui_web/controllers/api/stack_controller_test.exs @@ -198,4 +198,16 @@ defmodule EthuiWeb.Api.StackControllerTest do assert "public-stack2" in stack_slugs end end + + describe "stacks/:slug" do + test "returns a stack", %{conn: conn} do + stack = %Stack{id: 1, slug: "test-stack"} + Server.start(stack) + + conn = conn |> get(~p"/stacks/#{stack.slug}") + assert conn.status == 200 + response_data = json_response(conn, 200)["data"] + assert response_data["slug"] == stack.slug + end + end end