validate using org_id
All checks were successful
Build and Publish / build-release (push) Successful in 1m21s

This commit is contained in:
2026-05-15 14:16:43 -05:00
parent c371191bd8
commit 81a89c0151
2 changed files with 4 additions and 41 deletions

View File

@@ -218,29 +218,10 @@ defmodule CustomerServiceWeb.CustomerController do
end end
end end
defp dispatch_and_return(conn, command, %CustomerId{} = customer_id) do defp dispatch_and_return(conn, command, %CustomerId{org_id: org_id} = customer_id) do
case CustomerService.CommandedApp.dispatch(command, consistency: :strong) do case CustomerService.CommandedApp.dispatch(command, consistency: :strong) do
:ok -> :ok ->
case CustomerQueries.get_customer(to_string(customer_id)) do case CustomerQueries.get_customer(org_id, to_string(customer_id)) do
{:ok, customer} ->
conn |> put_status(:ok) |> json(%{data: customer_json(customer)})
{:error, :not_found} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: "customer created but not found in projection"})
end
{:error, reason} ->
conn |> put_status(:unprocessable_entity) |> json(%{error: inspect(reason)})
end
end
defp dispatch_and_return(conn, command, customer_id_string)
when is_binary(customer_id_string) do
case CustomerService.CommandedApp.dispatch(command, consistency: :strong) do
:ok ->
case CustomerQueries.get_customer(customer_id_string) do
{:ok, customer} -> {:ok, customer} ->
conn |> put_status(:ok) |> json(%{data: customer_json(customer)}) conn |> put_status(:ok) |> json(%{data: customer_json(customer)})

View File

@@ -176,28 +176,10 @@ defmodule CustomerServiceWeb.LeadController do
end end
end end
defp dispatch_and_return(conn, command, %LeadId{} = lead_id) do defp dispatch_and_return(conn, command, %LeadId{org_id: org_id} = lead_id) do
case CustomerService.CommandedApp.dispatch(command, consistency: :strong) do case CustomerService.CommandedApp.dispatch(command, consistency: :strong) do
:ok -> :ok ->
case LeadQueries.get_lead(to_string(lead_id)) do case LeadQueries.get_lead(org_id, to_string(lead_id)) do
{:ok, lead} ->
conn |> put_status(:ok) |> json(%{data: lead_json(lead)})
{:error, :not_found} ->
conn
|> put_status(:internal_server_error)
|> json(%{error: "lead created but not found in projection"})
end
{:error, reason} ->
conn |> put_status(:unprocessable_entity) |> json(%{error: inspect(reason)})
end
end
defp dispatch_and_return(conn, command, lead_id_string) when is_binary(lead_id_string) do
case CustomerService.CommandedApp.dispatch(command, consistency: :strong) do
:ok ->
case LeadQueries.get_lead(lead_id_string) do
{:ok, lead} -> {:ok, lead} ->
conn |> put_status(:ok) |> json(%{data: lead_json(lead)}) conn |> put_status(:ok) |> json(%{data: lead_json(lead)})