Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new API endpoint to retrieve the status of a single stack by its slug, including whether the stack is currently running. The implementation follows existing patterns for authentication, authorization, and error handling in the codebase.
- Adds
GET /stacks/:slugendpoint returning stack details (slug, urls, and running status) - Implements
is_slug_running?/1helper function in Server module to check stack status - Uses existing authorization patterns to ensure users can only access their own stacks
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/ethui_web/controllers/api/stack_controller.ex | Adds show/2 action with authorization, error handling, and response formatting consistent with other endpoints |
| lib/ethui/stacks/server.ex | Adds is_slug_running?/1 public API and handle_call implementation to query instances map |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 |
There was a problem hiding this comment.
The new show endpoint lacks test coverage. Based on existing tests in stack_controller_test.exs, the following scenarios should be tested:
- Successfully retrieving a stack owned by the authenticated user (returns 200 with status, slug, urls)
- Attempting to retrieve a stack owned by another user (returns 403 unauthorized)
- Attempting to retrieve a non-existent stack (returns 404 not found)
- Correctly reporting running vs stopped status based on Server state
These tests would ensure the authentication/authorization logic and response formatting work correctly.
| @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 |
There was a problem hiding this comment.
The new is_slug_running? function lacks test coverage. Based on existing tests in server_test.exs, tests should verify:
- Returns false when no stack with the given slug is running
- Returns true when a stack with the given slug is running
- Returns false after a stack is stopped
This would ensure the function correctly queries the instances map state.
No description provided.