add type specs and fix id issues
Some checks failed
Build and Publish / build-release (push) Failing after 37s

This commit is contained in:
2026-04-21 12:55:38 -05:00
parent f857a5f900
commit 2bf99bfb37
7 changed files with 78 additions and 42 deletions

View File

@@ -4,6 +4,12 @@ defmodule WorkloadService.Aggregates.ApplicationId do
Used to track which policy-service application this task belongs to. Used to track which policy-service application this task belongs to.
""" """
@type t :: %__MODULE__{
org_id: String.t(),
application_id: String.t(),
policy_type: String.t()
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:org_id, :application_id, :policy_type] defstruct [:org_id, :application_id, :policy_type]
@@ -49,4 +55,4 @@ defmodule WorkloadService.Aggregates.ApplicationId do
def decode(id), do: id def decode(id), do: id
end end
end end

View File

@@ -10,6 +10,15 @@ defmodule WorkloadService.Aggregates.Task do
end end
""" """
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t() | nil,
application_id: WorkloadService.Aggregates.ApplicationId.t() | nil,
task_info: map() | nil,
submission: map() | nil,
attachments: [String.t()],
status: String.t() | nil
}
@callback validate_submission(map()) :: :ok | {:error, term()} @callback validate_submission(map()) :: :ok | {:error, term()}
defmacro __using__(opts) do defmacro __using__(opts) do
@@ -55,8 +64,6 @@ defmodule WorkloadService.Aggregates.Task do
def execute(%__MODULE__{status: status}, %SubmitResponse{} = cmd) def execute(%__MODULE__{status: status}, %SubmitResponse{} = cmd)
when status in [nil, "created", "draft", "approved"] do when status in [nil, "created", "draft", "approved"] do
with :ok <- validate_submission(cmd.submission) do with :ok <- validate_submission(cmd.submission) do
new_status = if status == "approved", do: "draft", else: "draft"
%WorkloadService.Events.SubmissionUpdated{ %WorkloadService.Events.SubmissionUpdated{
id: cmd.id, id: cmd.id,
submission: cmd.submission, submission: cmd.submission,
@@ -78,9 +85,9 @@ defmodule WorkloadService.Aggregates.Task do
end end
@impl Aggregate @impl Aggregate
def execute(%__MODULE__{status: "approved"}, %CompleteTask{} = cmd) do def execute(%__MODULE__{status: "approved", id: id}, %CompleteTask{} = cmd) do
%WorkloadService.Events.TaskCompleted{ %WorkloadService.Events.TaskCompleted{
id: cmd.id, id: id,
completed_by: cmd.completed_by completed_by: cmd.completed_by
} }
end end

View File

@@ -4,6 +4,12 @@ defmodule WorkloadService.Aggregates.TaskId do
ID format: "org_id:type:task_id" (e.g., "test:quote:uuid") ID format: "org_id:type:task_id" (e.g., "test:quote:uuid")
""" """
@type t :: %__MODULE__{
org_id: String.t(),
type: String.t(),
task_id: String.t()
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:org_id, :type, :task_id] defstruct [:org_id, :type, :task_id]

View File

@@ -7,47 +7,53 @@ defmodule WorkloadService.Commands.QuoteTask do
@moduledoc """ @moduledoc """
Command to create a new quote task. Command to create a new quote task.
""" """
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t(),
application_id: WorkloadService.Aggregates.ApplicationId.t(),
task_info: map(),
attachments: [String.t()]
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:id, :application_id, :task_info, :attachments] defstruct [:id, :application_id, :task_info, :attachments]
def new(attrs) do
struct(__MODULE__, attrs)
end
end end
defmodule SubmitResponse do defmodule SubmitResponse do
@moduledoc """ @moduledoc """
Command to submit response for a quote task. Command to submit response for a quote task.
""" """
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t(),
submission: map(),
attachments: [String.t()]
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:id, :submission, :attachments] defstruct [:id, :submission, :attachments]
def new(attrs) do
struct(__MODULE__, attrs)
end
end end
defmodule ApproveSubmission do defmodule ApproveSubmission do
@moduledoc """ @moduledoc """
Command to approve submission for a quote task. Command to approve submission for a quote task.
""" """
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t()
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:id] defstruct [:id]
def new(attrs) do
struct(__MODULE__, attrs)
end
end end
defmodule CompleteTask do defmodule CompleteTask do
@moduledoc """ @moduledoc """
Command to complete a quote task. Command to complete a quote task.
""" """
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t(),
completed_by: String.t()
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:id, :completed_by] defstruct [:id, :completed_by]
def new(attrs) do
struct(__MODULE__, attrs)
end
end end
end end

View File

@@ -7,47 +7,53 @@ defmodule WorkloadService.Commands.SolicitationTask do
@moduledoc """ @moduledoc """
Command to create a new solicitation task. Command to create a new solicitation task.
""" """
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t(),
application_id: WorkloadService.Aggregates.ApplicationId.t(),
task_info: map(),
attachments: [String.t()]
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:id, :application_id, :task_info, :attachments] defstruct [:id, :application_id, :task_info, :attachments]
def new(attrs) do
struct(__MODULE__, attrs)
end
end end
defmodule SubmitResponse do defmodule SubmitResponse do
@moduledoc """ @moduledoc """
Command to submit response for a solicitation task. Command to submit response for a solicitation task.
""" """
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t(),
submission: map(),
attachments: [String.t()]
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:id, :submission, :attachments] defstruct [:id, :submission, :attachments]
def new(attrs) do
struct(__MODULE__, attrs)
end
end end
defmodule ApproveSubmission do defmodule ApproveSubmission do
@moduledoc """ @moduledoc """
Command to approve submission for a solicitation task. Command to approve submission for a solicitation task.
""" """
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t()
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:id] defstruct [:id]
def new(attrs) do
struct(__MODULE__, attrs)
end
end end
defmodule CompleteTask do defmodule CompleteTask do
@moduledoc """ @moduledoc """
Command to complete a solicitation task. Command to complete a solicitation task.
""" """
@type t :: %__MODULE__{
id: WorkloadService.Aggregates.TaskId.t(),
completed_by: String.t()
}
@derive Jason.Encoder @derive Jason.Encoder
defstruct [:id, :completed_by] defstruct [:id, :completed_by]
def new(attrs) do
struct(__MODULE__, attrs)
end
end end
end end

View File

@@ -29,7 +29,7 @@ defmodule WorkloadService.Handlers.TaskCompletedHandler do
{:ok, module} -> {:ok, module} ->
case Aggregate.aggregate_state( case Aggregate.aggregate_state(
WorkloadService.CommandedApp, WorkloadService.CommandedApp,
aggregate_module, module,
event.id event.id
) do ) do
nil -> nil ->

View File

@@ -4,6 +4,7 @@ defmodule WorkloadServiceWeb.TaskController do
alias WorkloadService.CommandedApp alias WorkloadService.CommandedApp
alias WorkloadService.Workload.Queries alias WorkloadService.Workload.Queries
alias WorkloadService.Aggregates.TaskId
alias WorkloadServiceWeb.Schemas.Task, as: S alias WorkloadServiceWeb.Schemas.Task, as: S
tags(["Tasks"]) tags(["Tasks"])
@@ -93,8 +94,9 @@ defmodule WorkloadServiceWeb.TaskController do
conn |> put_status(:not_found) |> json(%{error: "task not found"}) conn |> put_status(:not_found) |> json(%{error: "task not found"})
{:ok, %{status: "created"} = _task} -> {:ok, %{status: "created"} = _task} ->
task_id = TaskId.parse!(id)
command = %WorkloadService.Commands.QuoteTask.SubmitResponse{ command = %WorkloadService.Commands.QuoteTask.SubmitResponse{
id: id, id: task_id,
submission: %{ submission: %{
"quote_id" => params["quote_id"], "quote_id" => params["quote_id"],
"plans" => params["plans"], "plans" => params["plans"],
@@ -118,8 +120,9 @@ defmodule WorkloadServiceWeb.TaskController do
conn |> put_status(:not_found) |> json(%{error: "task not found"}) conn |> put_status(:not_found) |> json(%{error: "task not found"})
{:ok, %{status: "created"} = _task} -> {:ok, %{status: "created"} = _task} ->
task_id = TaskId.parse!(id)
command = %WorkloadService.Commands.SolicitationTask.SubmitResponse{ command = %WorkloadService.Commands.SolicitationTask.SubmitResponse{
id: id, id: task_id,
submission: %{ submission: %{
"recorded_by" => params["recorded_by"] || "system" "recorded_by" => params["recorded_by"] || "system"
}, },
@@ -166,7 +169,8 @@ defmodule WorkloadServiceWeb.TaskController do
conn |> put_status(:not_found) |> json(%{error: "task not found"}) conn |> put_status(:not_found) |> json(%{error: "task not found"})
{:ok, %{status: "draft"} = _task} -> {:ok, %{status: "draft"} = _task} ->
command = struct(command_module, id: id) task_id = TaskId.parse!(id)
command = struct(command_module, id: task_id)
dispatch_and_respond(conn, id, command) dispatch_and_respond(conn, id, command)
{:ok, _task} -> {:ok, _task} ->
@@ -214,7 +218,8 @@ defmodule WorkloadServiceWeb.TaskController do
conn |> put_status(:not_found) |> json(%{error: "task not found"}) conn |> put_status(:not_found) |> json(%{error: "task not found"})
{:ok, %{status: "approved"} = _task} -> {:ok, %{status: "approved"} = _task} ->
command = struct(command_module, id: id, completed_by: completed_by) task_id = TaskId.parse!(id)
command = struct(command_module, id: task_id, completed_by: completed_by)
dispatch_and_respond(conn, id, command) dispatch_and_respond(conn, id, command)
{:ok, _task} -> {:ok, _task} ->